Fix to describe new Zthes example instead of dinosauricon.
[idzebra-moved-to-github.git] / util / res.c
index a65e506..c1f5c12 100644 (file)
@@ -1,10 +1,26 @@
-/*
- * Copyright (C) 1994-2002, Index Data
- * All rights reserved.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Id: res.c,v 1.29 2002-04-04 14:14:14 adam Exp $
- */
+/* $Id: res.c,v 1.33 2002-10-22 09:37:56 heikki Exp $
+   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
+   Index Data Aps
+
+This file is part of the Zebra server.
+
+Zebra is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra.  If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -62,10 +78,13 @@ static void reread (Res r)
 
     val_buf = (char*) xmalloc (val_max);
 
+    if (!r->name)
+       return; 
+
     fr = fopen (r->name, "r");
     if (!fr)
     {
-        logf (LOG_WARN|LOG_ERRNO, "Cannot open %s", r->name);
+        logf (LOG_WARN|LOG_ERRNO, "Cannot open `%s'", r->name);
        return ;
     }
     while (1)
@@ -159,19 +178,26 @@ static void reread (Res r)
 Res res_open (const char *name, Res def_res)
 {
     Res r;
+
+    if (name)
+    {
 #ifdef WIN32
-    if (access (name, 4))
+        if (access (name, 4))
 #else
-    if (access (name, R_OK))
+        if (access (name, R_OK))
 #endif
-    {
-        logf (LOG_LOG|LOG_ERRNO, "Cannot access resource file `%s'", name);
-       return 0;
+        {
+            logf (LOG_WARN|LOG_ERRNO, "Cannot open `%s'", name);
+           return 0;
+        }
     }
     r = (Res) xmalloc (sizeof(*r));
     r->init = 0;
     r->first = r->last = NULL;
-    r->name = xstrdup (name);
+    if (name)
+        r->name = xstrdup (name);
+    else
+       r->name=0;
     r->def_res = def_res;
     return r;
 }
@@ -289,10 +315,12 @@ int res_write (Res r)
     assert (r);
     if (!r->init)
         reread (r);
+    if (!r->name)
+       return 0; /* ok, this was not from a file */
     fr = fopen (r->name, "w");
     if (!fr)
     {
-        logf (LOG_FATAL|LOG_ERRNO, "Cannot create %s", r->name);
+        logf (LOG_FATAL|LOG_ERRNO, "Cannot create `%s'", r->name);
         exit (1);
     }