]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use CUPS file IO routines for all buffered file IO.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sun, 30 Mar 2003 19:50:35 +0000 (19:50 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sun, 30 Mar 2003 19:50:35 +0000 (19:50 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@3535 7a7537e8-13f0-0310-91df-b6672ffda945

14 files changed:
scheduler/auth.c
scheduler/cert.c
scheduler/classes.c
scheduler/client.c
scheduler/conf.c
scheduler/conf.h
scheduler/file.c
scheduler/file.h
scheduler/ipp.c
scheduler/log.c
scheduler/main.c
scheduler/ppds.c
scheduler/printers.c
scheduler/server.c

index f7fd4db8533e0ef1189b8b7965024c6a17b5d049..26013b048a8967122b9f0e8f2c28cb4a014add22 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: auth.c,v 1.68 2003/01/31 17:48:23 mike Exp $"
+ * "$Id: auth.c,v 1.69 2003/03/30 19:50:33 mike Exp $"
  *
  *   Authorization routines for the Common UNIX Printing System (CUPS).
  *
@@ -765,24 +765,24 @@ GetMD5Passwd(const char *username,        /* I - Username */
              const char *group,                /* I - Group */
              char       passwd[33])    /* O - MD5 password string */
 {
-  FILE *fp;                            /* passwd.md5 file */
-  char filename[1024],                 /* passwd.md5 filename */
-       line[256],                      /* Line from file */
-       tempuser[33],                   /* User from file */
-       tempgroup[33];                  /* Group from file */
+  cups_file_t  *fp;                    /* passwd.md5 file */
+  char         filename[1024],         /* passwd.md5 filename */
+               line[256],              /* Line from file */
+               tempuser[33],           /* User from file */
+               tempgroup[33];          /* Group from file */
 
 
   LogMessage(L_DEBUG2, "GetMD5Passwd(username=\"%s\", group=\"%s\", passwd=%p)",
              username, group ? group : "(null)", passwd);
 
   snprintf(filename, sizeof(filename), "%s/passwd.md5", ServerRoot);
-  if ((fp = fopen(filename, "r")) == NULL)
+  if ((fp = cupsFileOpen(filename, "r")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to open %s - %s", filename, strerror(errno));
     return (NULL);
   }
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     if (sscanf(line, "%32[^:]:%32[^:]:%32s", tempuser, tempgroup, passwd) != 3)
     {
@@ -800,7 +800,7 @@ GetMD5Passwd(const char *username,  /* I - Username */
       LogMessage(L_DEBUG2, "Found MD5 user %s, group %s...", username,
                  tempgroup);
 
-      fclose(fp);
+      cupsFileClose(fp);
       return (passwd);
     }
   }
@@ -809,7 +809,7 @@ GetMD5Passwd(const char *username,  /* I - Username */
   * Didn't find a password entry - return NULL!
   */
 
-  fclose(fp);
+  cupsFileClose(fp);
   return (NULL);
 }
 
@@ -1643,5 +1643,5 @@ to64(char          *s,    /* O - Output string */
 
 
 /*
- * End of "$Id: auth.c,v 1.68 2003/01/31 17:48:23 mike Exp $".
+ * End of "$Id: auth.c,v 1.69 2003/03/30 19:50:33 mike Exp $".
  */
index d62adb9f56e33ba23c08c4fc85481106940b86da..651e7d7d0e39fe98ec3a8e62101bd58a33f74f82 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cert.c,v 1.16 2003/01/24 20:39:43 mike Exp $"
+ * "$Id: cert.c,v 1.17 2003/03/30 19:50:33 mike Exp $"
  *
  *   Authentication certificate routines for the Common UNIX
  *   Printing System (CUPS).
@@ -247,7 +247,7 @@ FindCert(const char *certificate)   /* I - Certificate */
 void
 InitCerts(void)
 {
-  FILE         *fp;                    /* /dev/random file */
+  cups_file_t  *fp;                    /* /dev/random file */
   unsigned     seed;                   /* Seed for random number generator */
   struct timeval tod;                  /* Time of day */
 
@@ -257,7 +257,7 @@ InitCerts(void)
   * the current time, as available...
   */
 
-  if ((fp = fopen("/dev/urandom", "rb")) == NULL)
+  if ((fp = cupsFileOpen("/dev/urandom", "rb")) == NULL)
   {
    /*
     * Get the time in usecs and use it as the initial seed...
@@ -274,12 +274,12 @@ InitCerts(void)
     * them as the seed...
     */
 
-    seed = getc(fp);
-    seed = (seed << 8) | getc(fp);
-    seed = (seed << 8) | getc(fp);
-    seed = (seed << 8) | getc(fp);
+    seed = cupsFileGetChar(fp);
+    seed = (seed << 8) | cupsFileGetChar(fp);
+    seed = (seed << 8) | cupsFileGetChar(fp);
+    seed = (seed << 8) | cupsFileGetChar(fp);
 
-    fclose(fp);
+    cupsFileClose(fp);
   }
 
   srandom(seed);
@@ -293,5 +293,5 @@ InitCerts(void)
 
 
 /*
- * End of "$Id: cert.c,v 1.16 2003/01/24 20:39:43 mike Exp $".
+ * End of "$Id: cert.c,v 1.17 2003/03/30 19:50:33 mike Exp $".
  */
index 32e482ecf7cb60132800f8cdfb54c44760aefcdf..eb936f66bcad17257f3483e020b41fcc0122300e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: classes.c,v 1.48 2003/03/10 19:27:50 mike Exp $"
+ * "$Id: classes.c,v 1.49 2003/03/30 19:50:33 mike Exp $"
  *
  *   Printer class routines for the Common UNIX Printing System (CUPS).
  *
@@ -322,7 +322,7 @@ FindClass(const char *name) /* I - Name of class */
 void
 LoadAllClasses(void)
 {
-  FILE         *fp;                    /* classes.conf file */
+  cups_file_t  *fp;                    /* classes.conf file */
   int          linenum;                /* Current line number */
   int          len;                    /* Length of line */
   char         line[1024],             /* Line from file */
@@ -339,7 +339,7 @@ LoadAllClasses(void)
   */
 
   snprintf(line, sizeof(line), "%s/classes.conf", ServerRoot);
-  if ((fp = fopen(line, "r")) == NULL)
+  if ((fp = cupsFileOpen(line, "r")) == NULL)
   {
     LogMessage(L_ERROR, "LoadAllClasses: Unable to open %s - %s", line,
                strerror(errno));
@@ -353,7 +353,7 @@ LoadAllClasses(void)
   linenum = 0;
   p       = NULL;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -565,7 +565,7 @@ LoadAllClasses(void)
     }
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -576,7 +576,7 @@ LoadAllClasses(void)
 void
 SaveAllClasses(void)
 {
-  FILE         *fp;                    /* classes.conf file */
+  cups_file_t  *fp;                    /* classes.conf file */
   char         temp[1024];             /* Temporary string */
   char         backup[1024];           /* classes.conf.O file */
   printer_t    *pclass;                /* Current printer class */
@@ -595,7 +595,7 @@ SaveAllClasses(void)
   if (rename(temp, backup))
     LogMessage(L_ERROR, "Unable to backup classes.conf - %s", strerror(errno));
 
-  if ((fp = fopen(temp, "w")) == NULL)
+  if ((fp = cupsFileOpen(temp, "w")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to save classes.conf - %s", strerror(errno));
 
@@ -610,8 +610,8 @@ SaveAllClasses(void)
   * Restrict access to the file...
   */
 
-  fchown(fileno(fp), User, Group);
-  fchmod(fileno(fp), 0600);
+  fchown(cupsFileNumber(fp), User, Group);
+  fchmod(cupsFileNumber(fp), 0600);
 
  /*
   * Write a small header to the file...
@@ -621,8 +621,8 @@ SaveAllClasses(void)
   curdate = gmtime(&curtime);
   strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
 
-  fputs("# Class configuration file for " CUPS_SVERSION "\n", fp);
-  fprintf(fp, "# Written by cupsd on %s\n", temp);
+  cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
+  cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
 
  /*
   * Write each local class known to the system...
@@ -644,50 +644,50 @@ SaveAllClasses(void)
     */
 
     if (pclass == DefaultPrinter)
-      fprintf(fp, "<DefaultClass %s>\n", pclass->name);
+      cupsFilePrintf(fp, "<DefaultClass %s>\n", pclass->name);
     else
-      fprintf(fp, "<Class %s>\n", pclass->name);
+      cupsFilePrintf(fp, "<Class %s>\n", pclass->name);
 
     if (pclass->info)
-      fprintf(fp, "Info %s\n", pclass->info);
+      cupsFilePrintf(fp, "Info %s\n", pclass->info);
 
     if (pclass->location)
-      fprintf(fp, "Location %s\n", pclass->location);
+      cupsFilePrintf(fp, "Location %s\n", pclass->location);
 
     if (pclass->state == IPP_PRINTER_STOPPED)
     {
-      fputs("State Stopped\n", fp);
-      fprintf(fp, "StateMessage %s\n", pclass->state_message);
+      cupsFilePuts(fp, "State Stopped\n");
+      cupsFilePrintf(fp, "StateMessage %s\n", pclass->state_message);
     }
     else
-      fputs("State Idle\n", fp);
+      cupsFilePuts(fp, "State Idle\n");
 
     if (pclass->accepting)
-      fputs("Accepting Yes\n", fp);
+      cupsFilePuts(fp, "Accepting Yes\n");
     else
-      fputs("Accepting No\n", fp);
+      cupsFilePuts(fp, "Accepting No\n");
 
-    fprintf(fp, "JobSheets %s %s\n", pclass->job_sheets[0],
-            pclass->job_sheets[1]);
+    cupsFilePrintf(fp, "JobSheets %s %s\n", pclass->job_sheets[0],
+                   pclass->job_sheets[1]);
 
     for (i = 0; i < pclass->num_printers; i ++)
-      fprintf(fp, "Printer %s\n", pclass->printers[i]->name);
+      cupsFilePrintf(fp, "Printer %s\n", pclass->printers[i]->name);
 
-    fprintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
-    fprintf(fp, "PageLimit %d\n", pclass->page_limit);
-    fprintf(fp, "KLimit %d\n", pclass->k_limit);
+    cupsFilePrintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
+    cupsFilePrintf(fp, "PageLimit %d\n", pclass->page_limit);
+    cupsFilePrintf(fp, "KLimit %d\n", pclass->k_limit);
 
     for (i = 0; i < pclass->num_users; i ++)
-      fprintf(fp, "%sUser %s\n", pclass->deny_users ? "Deny" : "Allow",
-              pclass->users[i]);
+      cupsFilePrintf(fp, "%sUser %s\n", pclass->deny_users ? "Deny" : "Allow",
+                     pclass->users[i]);
 
-    fputs("</Class>\n", fp);
+    cupsFilePuts(fp, "</Class>\n");
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
 /*
- * End of "$Id: classes.c,v 1.48 2003/03/10 19:27:50 mike Exp $".
+ * End of "$Id: classes.c,v 1.49 2003/03/30 19:50:33 mike Exp $".
  */
index 0ce20ad49ba62e9297b507e9385c121066f92cfd..858fbccaf4921e3b11fb9a7750d7831e7aa5d094 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: client.c,v 1.154 2003/03/28 22:27:59 mike Exp $"
+ * "$Id: client.c,v 1.155 2003/03/30 19:50:33 mike Exp $"
  *
  *   Client routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -2720,7 +2720,7 @@ get_file(client_t    *con,        /* I  - Client connection */
 static http_status_t                   /* O - Status */
 install_conf_file(client_t *con)       /* I - Connection */
 {
-  FILE         *in,                    /* Input file */
+  cups_file_t  *in,                    /* Input file */
                *out;                   /* Output file */
   char         buffer[1024];           /* Copy buffer */
   int          bytes;                  /* Number of bytes */
@@ -2757,36 +2757,36 @@ install_conf_file(client_t *con)        /* I - Connection */
   * Open the request file and new config file...
   */
 
-  if ((in = fopen(con->filename, "rb")) == NULL)
+  if ((in = cupsFileOpen(con->filename, "rb")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to open request file \"%s\" - %s",
                con->filename, strerror(errno));
     return (HTTP_SERVER_ERROR);
   }
 
-  if ((out = fopen(newfile, "wb")) == NULL)
+  if ((out = cupsFileOpen(newfile, "wb")) == NULL)
   {
-    fclose(in);
+    cupsFileClose(in);
     LogMessage(L_ERROR, "Unable to open config file \"%s\" - %s",
                newfile, strerror(errno));
     return (HTTP_SERVER_ERROR);
   }
 
-  fchmod(fileno(out), confinfo.st_mode);
-  fchown(fileno(out), confinfo.st_uid, confinfo.st_gid);
+  fchmod(cupsFileNumber(out), confinfo.st_mode);
+  fchown(cupsFileNumber(out), confinfo.st_uid, confinfo.st_gid);
 
  /*
   * Copy from the request to the new config file...
   */
 
-  while ((bytes = fread(buffer, 1, sizeof(buffer), in)) > 0)
-    if (fwrite(buffer, 1, bytes, out) < bytes)
+  while ((bytes = cupsFileRead(in, buffer, sizeof(buffer))) > 0)
+    if (cupsFileWrite(out, buffer, bytes) < bytes)
     {
       LogMessage(L_ERROR, "Unable to copy to config file \"%s\" - %s",
                 newfile, strerror(errno));
 
-      fclose(in);
-      fclose(out);
+      cupsFileClose(in);
+      cupsFileClose(out);
       unlink(newfile);
 
       return (HTTP_SERVER_ERROR);
@@ -2796,8 +2796,8 @@ install_conf_file(client_t *con)  /* I - Connection */
   * Close the files...
   */
 
-  fclose(in);
-  if (fclose(out))
+  cupsFileClose(in);
+  if (cupsFileClose(out))
   {
     LogMessage(L_ERROR, "Error file closing config file \"%s\" - %s",
                newfile, strerror(errno));
@@ -3291,5 +3291,5 @@ CDSAWriteFunc(SSLConnectionRef connection,        /* I  - SSL/TLS connection */
 
 
 /*
- * End of "$Id: client.c,v 1.154 2003/03/28 22:27:59 mike Exp $".
+ * End of "$Id: client.c,v 1.155 2003/03/30 19:50:33 mike Exp $".
  */
index afe8d62137d59ef11de2bee5e4acaf9706158092..4d80ce2c16046d0c4467f048ac861e99c24814c8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.c,v 1.127 2003/03/19 06:06:02 mike Exp $"
+ * "$Id: conf.c,v 1.128 2003/03/30 19:50:34 mike Exp $"
  *
  *   Configuration routines for the Common UNIX Printing System (CUPS).
  *
@@ -173,8 +173,8 @@ static var_t        variables[] =
  * Local functions...
  */
 
-static int     read_configuration(FILE *fp);
-static int     read_location(FILE *fp, char *name, int linenum);
+static int     read_configuration(cups_file_t *fp);
+static int     read_location(cups_file_t *fp, char *name, int linenum);
 static int     get_address(char *value, unsigned defaddress, int defport,
                            struct sockaddr_in *address);
 
@@ -191,7 +191,7 @@ int                                 /* O - 1 on success, 0 otherwise */
 ReadConfiguration(void)
 {
   int          i;                      /* Looping var */
-  FILE         *fp;                    /* Configuration file */
+  cups_file_t  *fp;                    /* Configuration file */
   int          status;                 /* Return status */
   char         temp[1024],             /* Temporary buffer */
                *slash;                 /* Directory separator */
@@ -407,12 +407,12 @@ ReadConfiguration(void)
   * Read the configuration file...
   */
 
-  if ((fp = fopen(ConfigurationFile, "r")) == NULL)
+  if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL)
     return (0);
 
   status = read_configuration(fp);
 
-  fclose(fp);
+  cupsFileClose(fp);
 
   if (!status)
     return (0);
@@ -666,7 +666,7 @@ ReadConfiguration(void)
  */
 
 static int                             /* O - 1 on success, 0 on failure */
-read_configuration(FILE *fp)           /* I - File to read from */
+read_configuration(cups_file_t *fp)    /* I - File to read from */
 {
   int          i;                      /* Looping var */
   int          linenum;                /* Current line number */
@@ -686,7 +686,7 @@ read_configuration(FILE *fp)                /* I - File to read from */
   dirsvc_poll_t        *poll;                  /* Polling data */
   struct sockaddr_in polladdr;         /* Polling address */
   location_t   *location;              /* Browse location */
-  FILE         *incfile;               /* Include file */
+  cups_file_t  *incfile;               /* Include file */
   char         incname[1024];          /* Include filename */
   static unsigned netmasks[4] =                /* Standard netmasks... */
   {
@@ -703,7 +703,7 @@ read_configuration(FILE *fp)                /* I - File to read from */
 
   linenum = 0;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -758,13 +758,13 @@ read_configuration(FILE *fp)              /* I - File to read from */
       else
         snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value);
 
-      if ((incfile = fopen(incname, "rb")) == NULL)
+      if ((incfile = cupsFileOpen(incname, "rb")) == NULL)
         LogMessage(L_ERROR, "Unable to include config file \"%s\" - %s",
                   incname, strerror(errno));
       else
       {
         read_configuration(incfile);
-       fclose(incfile);
+       cupsFileClose(incfile);
       }
     }
     else if (strcasecmp(name, "<Location") == 0)
@@ -1469,10 +1469,10 @@ read_configuration(FILE *fp)            /* I - File to read from */
  * 'read_location()' - Read a <Location path> definition.
  */
 
-static int                     /* O - New line number or 0 on error */
-read_location(FILE *fp,                /* I - Configuration file */
-              char *location,  /* I - Location name/path */
-             int  linenum)     /* I - Current line number */
+static int                             /* O - New line number or 0 on error */
+read_location(cups_file_t *fp,         /* I - Configuration file */
+              char        *location,   /* I - Location name/path */
+             int         linenum)      /* I - Current line number */
 {
   int          i;                      /* Looping var */
   location_t   *loc,                   /* New location */
@@ -1503,7 +1503,7 @@ read_location(FILE *fp,           /* I - Configuration file */
   parent->limit = AUTH_LIMIT_ALL;
   loc           = parent;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -2058,5 +2058,5 @@ CDSAGetServerCerts(void)
 
 
 /*
- * End of "$Id: conf.c,v 1.127 2003/03/19 06:06:02 mike Exp $".
+ * End of "$Id: conf.c,v 1.128 2003/03/30 19:50:34 mike Exp $".
  */
index 35fce4893888d5b11123a79f9898b80eb76155e9..626ddc7f645c442e7aa53d31f4cf9e20c2f42e8b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.h,v 1.55 2003/03/19 06:06:02 mike Exp $"
+ * "$Id: conf.h,v 1.56 2003/03/30 19:50:34 mike Exp $"
  *
  *   Configuration file definitions for the Common UNIX Printing System (CUPS)
  *   scheduler.
@@ -150,7 +150,7 @@ VAR int                     ClassifyOverride        VALUE(0),
                                        /* Run as unpriviledged user? */
                        PrintcapFormat          VALUE(PRINTCAP_BSD);
                                        /* Format of printcap file? */
-VAR FILE               *AccessFile             VALUE(NULL),
+VAR cups_file_t                *AccessFile             VALUE(NULL),
                                        /* Access log file */
                        *ErrorFile              VALUE(NULL),
                                        /* Error log file */
@@ -192,5 +192,5 @@ extern int  LogPage(job_t *job, const char *page);
 
 
 /*
- * End of "$Id: conf.h,v 1.55 2003/03/19 06:06:02 mike Exp $".
+ * End of "$Id: conf.h,v 1.56 2003/03/30 19:50:34 mike Exp $".
  */
index 59a6e1989866a84673909080f2e9e40cfbbd926c..e067f3d95e406eb9ce81fac9098838b4dcf3d979 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: file.c,v 1.1 2003/03/28 22:27:59 mike Exp $"
+ * "$Id: file.c,v 1.2 2003/03/30 19:50:34 mike Exp $"
  *
  *   File functions for the Common UNIX Printing System (CUPS).
  *
  * Contents:
  *
  *   cupsFileClose()   - Close a CUPS file.
+ *   cupsFileFlush()   - Flush pending output.
  *   cupsFileGetChar() - Get a single character from a file.
  *   cupsFileGets()    - Get a CR and/or LF-terminated line.
  *   cupsFileOpen()    - Open a CUPS file.
  *   cupsFilePrintf()  - Write a formatted string.
+ *   cupsFilePutChar() - Write a character.
  *   cupsFilePuts()    - Write a string.
+ *   cupsFileRead()    - Read from a file.
+ *   cupsFileSeek()    - Seek in a file.
+ *   cupsFileWrite()   - Write to a file.
  *   cups_fill()       - Fill the input buffer...
  *   cups_read()       - Read from a file descriptor.
  *   cups_write()      - Write to a file descriptor.
@@ -94,6 +99,9 @@ cupsFileClose(cups_file_t *fp)                /* I - CUPS file */
     inflateEnd(&fp->stream);
 #endif /* HAVE_LIBZ */
 
+  if (fp->mode == 'w')
+    cupsFileFlush(fp);
+
  /*
   * Save the file descriptor we used and free memory...
   */
@@ -110,6 +118,37 @@ cupsFileClose(cups_file_t *fp)             /* I - CUPS file */
 }
 
 
+/*
+ * 'cupsFileFlush()' - Flush pending output.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsFileFlush(cups_file_t *fp)         /* I - CUPS file */
+{
+  int  bytes;                          /* Bytes to write */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (!fp || fp->mode != 'w')
+    return (-1);
+
+  bytes = fp->ptr - fp->buf;
+
+  if (bytes > 0)
+  {
+    if (cups_write(fp->fd, fp->buf, bytes) < bytes)
+      return (-1);
+
+    fp->ptr = fp->buf;
+  }
+   
+  return (0);
+}
+
+
 /*
  * 'cupsFileGetChar()' - Get a single character from a file.
  */
@@ -227,7 +266,7 @@ cupsFileOpen(const char *filename,  /* I - Name of file */
   * Range check input...
   */
 
-  if (!filename || !mode || (*mode != 'r' && *mode != 'w'))
+  if (!filename || !mode || (*mode != 'r' && *mode != 'w' && *mode != 'a'))
     return (NULL);
 
  /*
@@ -241,10 +280,23 @@ cupsFileOpen(const char *filename,        /* I - Name of file */
   * Open the file...
   */
 
-  if (*mode == 'r')
-    o = O_RDONLY;
-  else
-    o = O_WRONLY | O_TRUNC | O_CREAT;
+  switch (*mode)
+  {
+    case 'a' :
+        o = O_RDWR | O_CREAT;
+       fp->mode = 'w';
+        break;
+
+    case 'r' :
+       o        = O_RDONLY;
+       fp->mode = 'r';
+       break;
+
+    case 'w' :
+        o = O_WRONLY | O_TRUNC | O_CREAT;
+       fp->mode = 'w';
+        break;
+  }
 
   if ((fp->fd = open(filename, o, 0644)) < 0)
   {
@@ -256,7 +308,16 @@ cupsFileOpen(const char *filename, /* I - Name of file */
     return (NULL);
   }
 
-  fp->mode = *mode;
+  if (*mode == 'a')
+    fp->pos = lseek(fp->fd, 0, SEEK_END);
+  else
+    fp->pos = 0;
+
+  if (*mode != 'r')
+  {
+    fp->ptr = fp->buf;
+    fp->end = fp->buf + sizeof(fp->buf);
+  }
 
   return (fp);
 }
@@ -273,16 +334,60 @@ cupsFilePrintf(cups_file_t *fp,           /* I - CUPS file */
 {
   va_list      ap;                     /* Argument list */
   int          bytes;                  /* Formatted size */
+  char         buf[2048];              /* Formatted text */
 
 
   if (!fp || !format || fp->mode != 'w')
     return (-1);
 
   va_start(ap, format);
-  bytes = vsnprintf(fp->buf, sizeof(fp->buf), format, ap);
+  bytes = vsnprintf(buf, sizeof(buf), format, ap);
   va_end(ap);
 
-  return (cups_write(fp->fd, fp->buf, bytes));
+  if ((fp->ptr + bytes) > fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  fp->pos += bytes;
+
+  if (bytes > sizeof(fp->buf))
+    return (cups_write(fp->fd, buf, bytes));
+  else
+  {
+    memcpy(fp->ptr, buf, bytes);
+    fp->ptr += bytes;
+    return (bytes);
+  }
+}
+
+
+/*
+ * 'cupsFilePutChar()' - Write a character.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsFilePutChar(cups_file_t *fp,       /* I - CUPS file */
+                int         c)         /* I - Character to write */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!fp || fp->mode != 'w')
+    return (-1);
+
+ /*
+  * Buffer it up...
+  */
+
+  if (fp->ptr >= fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  *(fp->ptr) ++ = c;
+  fp->pos ++;
+
+  return (0);
 }
 
 
@@ -294,6 +399,9 @@ int                                 /* O - Number of bytes written or -1 */
 cupsFilePuts(cups_file_t *fp,          /* I - CUPS file */
              const char  *s)           /* I - String to write */
 {
+  int  bytes;                          /* Bytes to write */
+
+
  /*
   * Range check input...
   */
@@ -305,7 +413,22 @@ cupsFilePuts(cups_file_t *fp,              /* I - CUPS file */
   * Write the string...
   */
 
-  return (cups_write(fp->fd, s, strlen(s)));
+  bytes = strlen(s);
+
+  if ((fp->ptr + bytes) > fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  fp->pos += bytes;
+
+  if (bytes > sizeof(fp->buf))
+    return (cups_write(fp->fd, s, bytes));
+  else
+  {
+    memcpy(fp->ptr, s, bytes);
+    fp->ptr += bytes;
+    return (bytes);
+  }
 }
 
 
@@ -465,6 +588,43 @@ cupsFileSeek(cups_file_t *fp,              /* I - CUPS file */
 }
 
 
+/*
+ * 'cupsFileWrite()' - Write to a file.
+ */
+
+int                                    /* O - Number of bytes written */
+cupsFileWrite(cups_file_t *fp,         /* I - CUPS file */
+              const char  *buf,                /* I - Buffer */
+             int         bytes)        /* I - Number of bytes to write */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!fp || !buf || bytes <= 0 || fp->mode != 'w')
+    return (-1);
+
+ /*
+  * Write the buffer...
+  */
+
+  if ((fp->ptr + bytes) > fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  fp->pos += bytes;
+
+  if (bytes > sizeof(fp->buf))
+    return (cups_write(fp->fd, buf, bytes));
+  else
+  {
+    memcpy(fp->ptr, buf, bytes);
+    fp->ptr += bytes;
+    return (bytes);
+  }
+}
+
+
 /*
  * 'cups_fill()' - Fill the input buffer...
  */
@@ -806,5 +966,5 @@ cups_write(int        fd,           /* I - File descriptor */
 
 
 /*
- * End of "$Id: file.c,v 1.1 2003/03/28 22:27:59 mike Exp $".
+ * End of "$Id: file.c,v 1.2 2003/03/30 19:50:34 mike Exp $".
  */
index 05cb184ebaf1bca02b15a6c470e3ef964b56abcc..f339470d7b42a97d790eb38f17632dae43c22a41 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: file.h,v 1.1 2003/03/28 22:28:00 mike Exp $"
+ * "$Id: file.h,v 1.2 2003/03/30 19:50:34 mike Exp $"
  *
  *   File definitions for the Common UNIX Printing System (CUPS).
  *
@@ -75,13 +75,19 @@ typedef struct
  */
 
 extern int             cupsFileClose(cups_file_t *fp);
+#define                        cupsFileCompressed(fp) (fp)->compressed
+extern int             cupsFileFlush(cups_file_t *fp);
 extern int             cupsFileGetChar(cups_file_t *fp);
 extern char            *cupsFileGets(cups_file_t *fp, char *buf, int buflen);
+#define                        cupsFileNumber(fp) (fp)->fd
 extern cups_file_t     *cupsFileOpen(const char *filename, const char *mode);
 extern int             cupsFilePrintf(cups_file_t *fp, const char *format, ...);
+extern int             cupsFilePutChar(cups_file_t *fp, int c);
 extern int             cupsFilePuts(cups_file_t *fp, const char *s);
 extern int             cupsFileRead(cups_file_t *fp, char *buf, int bytes);
 extern int             cupsFileSeek(cups_file_t *fp, int pos);
+#define                        cupsFileTell(fp) (fp)->pos
+extern int             cupsFileWrite(cups_file_t *fp, const char *buf, int bytes);
 
 
 #  ifdef _cplusplus
@@ -90,5 +96,5 @@ extern int            cupsFileSeek(cups_file_t *fp, int pos);
 #endif /* !_CUPS_FILE_H_ */
 
 /*
- * End of "$Id: file.h,v 1.1 2003/03/28 22:28:00 mike Exp $".
+ * End of "$Id: file.h,v 1.2 2003/03/30 19:50:34 mike Exp $".
  */
index c3ba8eaf4811a9cb135e0da92d4406ff00579fb3..844d4d9e1e5b1ba8f95818093417c8e889dffddf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c,v 1.199 2003/03/28 17:31:22 mike Exp $"
+ * "$Id: ipp.c,v 1.200 2003/03/30 19:50:34 mike Exp $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -988,11 +988,7 @@ add_printer(client_t        *con,  /* I - Client connection */
   int                  port;           /* Port portion of URI */
   printer_t            *printer;       /* Printer/class */
   ipp_attribute_t      *attr;          /* Printer attribute */
-#ifdef HAVE_LIBZ
-  gzFile               fp;             /* Script/PPD file */
-#else
-  FILE                 *fp;            /* Script/PPD file */
-#endif /* HAVE_LIBZ */
+  cups_file_t          *fp;            /* Script/PPD file */
   char                 line[1024];     /* Line from file... */
   char                 srcfile[1024],  /* Source Script/PPD file */
                        dstfile[1024];  /* Destination Script/PPD file */
@@ -1307,24 +1303,15 @@ add_printer(client_t        *con,       /* I - Client connection */
              printer->name);
     unlink(dstfile);
   }
-#ifdef HAVE_LIBZ
-  else if (srcfile[0] && (fp = gzopen(srcfile, "rb")) != NULL)
-#else
-  else if (srcfile[0] && (fp = fopen(srcfile, "rb")) != NULL)
-#endif /* HAVE_LIBZ */
+  else if (srcfile[0] && (fp = cupsFileOpen(srcfile, "rb")) != NULL)
   {
    /*
     * Yes; get the first line from it...
     */
 
     line[0] = '\0';
-#ifdef HAVE_LIBZ
-    gzgets(fp, line, sizeof(line));
-    gzclose(fp);
-#else
-    fgets(line, sizeof(line), fp);
-    fclose(fp);
-#endif /* HAVE_LIBZ */
+    cupsFileGets(fp, line, sizeof(line));
+    cupsFileClose(fp);
 
    /*
     * Then see what kind of file it is...
@@ -2597,8 +2584,8 @@ copy_banner(client_t   *con,      /* I - Client connection */
   int          kbytes;         /* Size of banner file in kbytes */
   char         filename[1024]; /* Job filename */
   banner_t     *banner;        /* Pointer to banner */
-  FILE         *in;            /* Input file */
-  FILE         *out;           /* Output file */
+  cups_file_t  *in;            /* Input file */
+  cups_file_t  *out;           /* Output file */
   int          ch;             /* Character from file */
   char         attrname[255],  /* Name of attribute */
                *s;             /* Pointer into name */
@@ -2626,7 +2613,7 @@ copy_banner(client_t   *con,      /* I - Client connection */
 
   snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
            job->num_files);
-  if ((out = fopen(filename, "w")) == NULL)
+  if ((out = cupsFileOpen(filename, "w")) == NULL)
   {
     LogMessage(L_ERROR, "copy_banner: Unable to create banner job file %s - %s",
                filename, strerror(errno));
@@ -2634,8 +2621,8 @@ copy_banner(client_t   *con,      /* I - Client connection */
     return (0);
   }
 
-  fchmod(fileno(out), 0640);
-  fchown(fileno(out), User, Group);
+  fchmod(cupsFileNumber(out), 0640);
+  fchown(cupsFileNumber(out), User, Group);
 
   if (con->language)
   {
@@ -2679,9 +2666,9 @@ copy_banner(client_t   *con,      /* I - Client connection */
     snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name);
   }
 
-  if ((in = fopen(filename, "r")) == NULL)
+  if ((in = cupsFileOpen(filename, "r")) == NULL)
   {
-    fclose(out);
+    cupsFileClose(out);
     unlink(filename);
     LogMessage(L_ERROR, "copy_banner: Unable to open banner template file %s - %s",
                filename, strerror(errno));
@@ -2693,14 +2680,14 @@ copy_banner(client_t   *con,    /* I - Client connection */
   * Parse the file to the end...
   */
 
-  while ((ch = getc(in)) != EOF)
+  while ((ch = cupsFileGetChar(in)) != EOF)
     if (ch == '{')
     {
      /*
       * Get an attribute name...
       */
 
-      for (s = attrname; (ch = getc(in)) != EOF;)
+      for (s = attrname; (ch = cupsFileGetChar(in)) != EOF;)
         if (!isalpha(ch) && ch != '-' && ch != '?')
           break;
        else if (s < (attrname + sizeof(attrname) - 1))
@@ -2716,9 +2703,7 @@ copy_banner(client_t   *con,      /* I - Client connection */
         * Ignore { followed by stuff that is not an attribute name...
        */
 
-        putc('{', out);
-       fputs(attrname, out);
-       putc(ch, out);
+        cupsFilePrintf(out, "{%s}", attrname);
        continue;
       }
 
@@ -2748,9 +2733,7 @@ copy_banner(client_t   *con,      /* I - Client connection */
           * Nope, write to file as-is; probably a PostScript procedure...
          */
 
-         putc('{', out);
-         fputs(attrname, out);
-         putc('}', out);
+         cupsFilePrintf(out, "{%s}", attrname);
         }
 
         continue;
@@ -2763,33 +2746,33 @@ copy_banner(client_t   *con,    /* I - Client connection */
       for (i = 0; i < attr->num_values; i ++)
       {
        if (i)
-         putc(',', out);
+         cupsFilePutChar(out, ',');
 
        switch (attr->value_tag)
        {
          case IPP_TAG_INTEGER :
          case IPP_TAG_ENUM :
              if (strncmp(s, "time-at-", 8) == 0)
-               fputs(GetDateTime(attr->values[i].integer), out);
+               cupsFilePuts(out, GetDateTime(attr->values[i].integer));
              else
-               fprintf(out, "%d", attr->values[i].integer);
+               cupsFilePrintf(out, "%d", attr->values[i].integer);
              break;
 
          case IPP_TAG_BOOLEAN :
-             fprintf(out, "%d", attr->values[i].boolean);
+             cupsFilePrintf(out, "%d", attr->values[i].boolean);
              break;
 
          case IPP_TAG_NOVALUE :
-             fputs("novalue", out);
+             cupsFilePuts(out, "novalue");
              break;
 
          case IPP_TAG_RANGE :
-             fprintf(out, "%d-%d", attr->values[i].range.lower,
+             cupsFilePrintf(out, "%d-%d", attr->values[i].range.lower,
                      attr->values[i].range.upper);
              break;
 
          case IPP_TAG_RESOLUTION :
-             fprintf(out, "%dx%d%s", attr->values[i].resolution.xres,
+             cupsFilePrintf(out, "%dx%d%s", attr->values[i].resolution.xres,
                      attr->values[i].resolution.yres,
                      attr->values[i].resolution.units == IPP_RES_PER_INCH ?
                          "dpi" : "dpc");
@@ -2814,17 +2797,17 @@ copy_banner(client_t   *con,    /* I - Client connection */
                {
                  if (*p == '(' || *p == ')' || *p == '\\')
                  {
-                   putc('\\', out);
-                   putc(*p, out);
+                   cupsFilePutChar(out, '\\');
+                   cupsFilePutChar(out, *p);
                  }
                  else if (*p < 32 || *p > 126)
-                   fprintf(out, "\\%03o", *p);
+                   cupsFilePrintf(out, "\\%03o", *p);
                  else
-                   putc(*p, out);
+                   cupsFilePutChar(out, *p);
                }
              }
              else
-               fputs(attr->values[i].string.text, out);
+               cupsFilePuts(out, attr->values[i].string.text);
              break;
 
           default :
@@ -2834,24 +2817,24 @@ copy_banner(client_t   *con,    /* I - Client connection */
     }
     else if (ch == '\\')       /* Quoted char */
     {
-      ch = getc(in);
+      ch = cupsFileGetChar(in);
 
       if (ch != '{')           /* Only do special handling for \{ */
-        putc('\\', out);
+        cupsFilePutChar(out, '\\');
 
-      putc(ch, out);
+      cupsFilePutChar(out, ch);
     }
     else
-      putc(ch, out);
+      cupsFilePutChar(out, ch);
 
-  fclose(in);
+  cupsFileClose(in);
 
   kbytes = (ftell(out) + 1023) / 1024;
 
   if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
     attr->values[0].integer += kbytes;
 
-  fclose(out);
+  cupsFileClose(out);
 
   return (kbytes);
 }
@@ -6308,5 +6291,5 @@ validate_user(client_t   *con,            /* I - Client connection */
 
 
 /*
- * End of "$Id: ipp.c,v 1.199 2003/03/28 17:31:22 mike Exp $".
+ * End of "$Id: ipp.c,v 1.200 2003/03/30 19:50:34 mike Exp $".
  */
index 47413ab0e4d9b73b89557a8230578d0ee7e2717e..6341a9708c73fdb14b03b0b424028997dffd39ed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: log.c,v 1.30 2003/03/10 15:05:00 mike Exp $"
+ * "$Id: log.c,v 1.31 2003/03/30 19:50:35 mike Exp $"
  *
  *   Log file routines for the Common UNIX Printing System (CUPS).
  *
@@ -46,7 +46,7 @@
  * Local functions...
  */
 
-static int     check_log_file(FILE **, const char *);
+static int     check_log_file(cups_file_t **, const char *);
 
 
 /*
@@ -187,7 +187,7 @@ LogMessage(int        level,        /* I - Log level */
   * Print the log level and date/time...
   */
 
-  fprintf(ErrorFile, "%c %s ", levels[level], GetDateTime(time(NULL)));
+  cupsFilePrintf(ErrorFile, "%c %s ", levels[level], GetDateTime(time(NULL)));
 
  /*
   * Then the log message...
@@ -201,11 +201,12 @@ LogMessage(int        level,      /* I - Log level */
   * Then a newline...
   */
 
-  fputs(line, ErrorFile);
   if (len > 0 && line[len - 1] != '\n')
-    putc('\n', ErrorFile);
+    cupsFilePrintf(ErrorFile, "%s\n", line);
+  else
+    cupsFilePuts(ErrorFile, line);
 
-  fflush(ErrorFile);
+  cupsFileFlush(ErrorFile);
 
   ReleaseSignals();
 
@@ -267,12 +268,12 @@ LogPage(job_t       *job, /* I - Job being printed */
   *        billing hostname
   */
 
-  fprintf(PageFile, "%s %s %d %s %s %s %s\n", job->printer->name,
-          job->username ? job->username : "-",
-          job->id, GetDateTime(time(NULL)), page,
-         billing ? billing->values[0].string.text : "-",
-          hostname->values[0].string.text);
-  fflush(PageFile);
+  cupsFilePrintf(PageFile, "%s %s %d %s %s %s %s\n", job->printer->name,
+                job->username ? job->username : "-",
+                job->id, GetDateTime(time(NULL)), page,
+                billing ? billing->values[0].string.text : "-",
+                hostname->values[0].string.text);
+  cupsFileFlush(PageFile);
 
   ReleaseSignals();
 
@@ -343,12 +344,12 @@ LogRequest(client_t      *con,    /* I - Request to log */
   * Write a log of the request in "common log format"...
   */
 
-  fprintf(AccessFile, "%s - %s %s \"%s %s HTTP/%d.%d\" %d %d\n",
-          con->http.hostname, con->username[0] != '\0' ? con->username : "-",
-         GetDateTime(con->start), states[con->operation], con->uri,
-         con->http.version / 100, con->http.version % 100,
-         code, con->bytes);
-  fflush(AccessFile);
+  cupsFilePrintf(AccessFile, "%s - %s %s \"%s %s HTTP/%d.%d\" %d %d\n",
+                con->http.hostname, con->username[0] != '\0' ? con->username : "-",
+                GetDateTime(con->start), states[con->operation], con->uri,
+                con->http.version / 100, con->http.version % 100,
+                code, con->bytes);
+  cupsFileFlush(AccessFile);
 
   ReleaseSignals();
 
@@ -361,8 +362,8 @@ LogRequest(client_t      *con,      /* I - Request to log */
  */
 
 static int                             /* O  - 1 if log file open */
-check_log_file(FILE       **log,       /* IO - Log file */
-              const char *logname)     /* I  - Log filename */
+check_log_file(cups_file_t **log,      /* IO - Log file */
+              const char  *logname)    /* I  - Log filename */
 {
   char backname[1024],                 /* Backup log filename */
        filename[1024],                 /* Formatted log filename */
@@ -381,7 +382,7 @@ check_log_file(FILE       **log,    /* IO - Log file */
   */
 
   if (*log == NULL ||
-      (ftell(*log) > MaxLogSize && MaxLogSize > 0))
+      (cupsFileTell(*log) > MaxLogSize && MaxLogSize > 0))
   {
    /*
     * Handle format strings...
@@ -441,24 +442,24 @@ check_log_file(FILE       **log,  /* IO - Log file */
     * Nope, open the log file...
     */
 
-    if ((*log = fopen(filename, "a")) == NULL)
+    if ((*log = cupsFileOpen(filename, "a")) == NULL)
       return (0);
 
-    fchown(fileno(*log), User, Group);
-    fchmod(fileno(*log), LogFilePerm);
+    fchown(cupsFileNumber(*log), User, Group);
+    fchmod(cupsFileNumber(*log), LogFilePerm);
   }
 
  /*
   * Do we need to rotate the log?
   */
 
-  if (ftell(*log) > MaxLogSize && MaxLogSize > 0)
+  if (cupsFileTell(*log) > MaxLogSize && MaxLogSize > 0)
   {
    /*
     * Rotate log file...
     */
 
-    fclose(*log);
+    cupsFileClose(*log);
 
     strcpy(backname, filename);
     strlcat(backname, ".O", sizeof(backname));
@@ -466,11 +467,11 @@ check_log_file(FILE       **log,  /* IO - Log file */
     unlink(backname);
     rename(filename, backname);
 
-    if ((*log = fopen(filename, "a")) == NULL)
+    if ((*log = cupsFileOpen(filename, "a")) == NULL)
       return (0);
 
-    fchown(fileno(*log), User, Group);
-    fchmod(fileno(*log), LogFilePerm);
+    fchown(cupsFileNumber(*log), User, Group);
+    fchmod(cupsFileNumber(*log), LogFilePerm);
   }
 
   return (1);
@@ -478,5 +479,5 @@ check_log_file(FILE       **log,    /* IO - Log file */
 
 
 /*
- * End of "$Id: log.c,v 1.30 2003/03/10 15:05:00 mike Exp $".
+ * End of "$Id: log.c,v 1.31 2003/03/30 19:50:35 mike Exp $".
  */
index e2c30e0e969bf2a55c6baab2dfdb6918f0bb11a8..ab560ab05ab13089117c561d70ea03585f82d72c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c,v 1.98 2003/03/21 15:09:34 mike Exp $"
+ * "$Id: main.c,v 1.99 2003/03/30 19:50:35 mike Exp $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
@@ -100,7 +100,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   struct sigaction     action;         /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
 #ifdef __sgi
-  FILE                 *fp;            /* Fake lpsched lock file */
+  cups_file_t          *fp;            /* Fake lpsched lock file */
 #endif /* __sgi */
 
 
@@ -350,7 +350,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   * printing...
   */
 
-  if ((fp = fopen("/var/spool/lp/SCHEDLOCK", "a")) == NULL)
+  if ((fp = cupsFileOpen("/var/spool/lp/SCHEDLOCK", "w")) == NULL)
   {
     syslog(LOG_LPR, "Unable to create fake lpsched lock file "
                     "\"/var/spool/lp/SCHEDLOCK\"\' - %s!",
@@ -358,10 +358,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
   }
   else
   {
-    fclose(fp);
+    fchmod(cupsFileNumber(fp), 0644);
+    fchown(cupsFileNumber(fp), User, Group);
 
-    chmod("/var/spool/lp/SCHEDLOCK", 0644);
-    chown("/var/spool/lp/SCHEDLOCK", User, Group);
+    cupsFileClose(fp);
   }
 #endif /* __sgi */
 
@@ -1028,13 +1028,13 @@ sigterm_handler(int sig)                /* I - Signal */
   FreeAllJobs();
 
   if (AccessFile != NULL)
-    fclose(AccessFile);
+    cupsFileClose(AccessFile);
 
   if (ErrorFile != NULL)
-    fclose(ErrorFile);
+    cupsFileClose(ErrorFile);
 
   if (PageFile != NULL)
-    fclose(PageFile);
+    cupsFileClose(PageFile);
 
   DeleteAllLocations();
 
@@ -1091,5 +1091,5 @@ usage(void)
 
 
 /*
- * End of "$Id: main.c,v 1.98 2003/03/21 15:09:34 mike Exp $".
+ * End of "$Id: main.c,v 1.99 2003/03/30 19:50:35 mike Exp $".
  */
index 3e98f616ed9dd1cd78738825bb5cd074e4d8f4fa..2c9e7deadc3eea92f4ad685af13eb038e81418ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppds.c,v 1.27 2002/12/17 19:00:17 swdev Exp $"
+ * "$Id: ppds.c,v 1.28 2003/03/30 19:50:35 mike Exp $"
  *
  *   PPD scanning routines for the Common UNIX Printing System (CUPS).
  *
 #include "cupsd.h"
 #include <ctype.h>
 
-#ifdef HAVE_LIBZ
-#  include <zlib.h>
-#else
-#  define gzFile       FILE *
-#  define gzclose      fclose
-#  define gzread(f,b,l)        fread((b), 1, (l), (f))
-#  define gzopen       fopen
-#endif /* HAVE_LIBZ */
-
 
 /*
  * PPD information structures...
@@ -71,19 +62,6 @@ typedef struct
 } ppd_info_t;
 
 
-/*
- * Buffered file structure...
- */
-
-typedef struct
-{
-  gzFile       fp;                     /* Pointer to file */
-  char         *ptr,                   /* Pointer in buffer */
-               *end,                   /* End of buffer */
-               buf[1024];              /* Buffer */
-} buf_t;
-
-
 /*
  * Local globals...
  */
@@ -98,11 +76,9 @@ static int           changed_ppd;    /* Did we change the PPD database? */
  * Local functions...
  */
 
-static int     buf_read(buf_t *fp);
 static int     compare_names(const ppd_info_t *p0, const ppd_info_t *p1);
 static int     compare_ppds(const ppd_info_t *p0, const ppd_info_t *p1);
 static void    load_ppds(const char *d, const char *p);
-static char    *ppd_gets(buf_t *fp, char *buf, int buflen);
 
 
 /*
@@ -110,13 +86,13 @@ static char        *ppd_gets(buf_t *fp, char *buf, int buflen);
  */
 
 void
-LoadPPDs(const char *d)                /* I - Directory to scan... */
+LoadPPDs(const char *d)                        /* I - Directory to scan... */
 {
-  int          i;              /* Looping var */
-  ppd_info_t   *ppd;           /* Current PPD file */
-  FILE         *fp;            /* ppds.dat file */
-  struct stat  fileinfo;       /* ppds.dat information */
-  char         filename[1024]; /* ppds.dat filename */
+  int          i;                      /* Looping var */
+  ppd_info_t   *ppd;                   /* Current PPD file */
+  cups_file_t  *fp;                    /* ppds.dat file */
+  struct stat  fileinfo;               /* ppds.dat information */
+  char         filename[1024];         /* ppds.dat filename */
 
 
  /*
@@ -145,15 +121,15 @@ LoadPPDs(const char *d)           /* I - Directory to scan... */
       num_ppds   = 0;
       alloc_ppds = 0;
     }
-    else if ((fp = fopen(filename, "rb")) != NULL)
+    else if ((fp = cupsFileOpen(filename, "rb")) != NULL)
     {
       for (i = num_ppds, ppd = ppds; i > 0; i --, ppd ++)
       {
-        fread(&(ppd->record), 1, sizeof(ppd_rec_t), fp);
+        cupsFileRead(fp, (char *)&(ppd->record), sizeof(ppd_rec_t));
        ppd->found = 0;
       }
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       LogMessage(L_INFO, "LoadPPDs: Read \"%s\", %d PPDs...", filename,
                  num_ppds);
@@ -212,12 +188,12 @@ LoadPPDs(const char *d)           /* I - Directory to scan... */
 
   if (changed_ppd)
   {
-    if ((fp = fopen(filename, "wb")) != NULL)
+    if ((fp = cupsFileOpen(filename, "wb")) != NULL)
     {
       for (i = num_ppds, ppd = ppds; i > 0; i --, ppd ++)
-       fwrite(&(ppd->record), 1, sizeof(ppd_rec_t), fp);
+       cupsFileWrite(fp, (char *)&(ppd->record), sizeof(ppd_rec_t));
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       LogMessage(L_INFO, "LoadPPDs: Wrote \"%s\", %d PPDs...", filename,
                 num_ppds);
@@ -278,31 +254,6 @@ LoadPPDs(const char *d)            /* I - Directory to scan... */
 }
 
 
-/*
- * 'buf_read()' - Read a buffer of data into memory...
- */
-
-static int                     /* O - Number of bytes read */
-buf_read(buf_t *fp)            /* I - File to read from */
-{
-  int  count;                  /* Number of bytes read */
-
-
-  if ((count = gzread(fp->fp, fp->buf, sizeof(fp->buf))) > 0)
-  {
-    fp->ptr = fp->buf;
-    fp->end = fp->buf + count;
-  }
-  else
-  {
-    fp->ptr = NULL;
-    fp->end = NULL;
-  }
-
-  return (count);
-}
-
-
 /*
  * 'compare_names()' - Compare PPD filenames for sorting.
  */
@@ -452,7 +403,7 @@ load_ppds(const char *d,            /* I - Actual directory */
           const char *p)               /* I - Virtual path in name */
 {
   int          i;                      /* Looping var */
-  buf_t                fp;                     /* Pointer to file */
+  cups_file_t  *fp;                    /* Pointer to file */
   DIR          *dir;                   /* Directory pointer */
   DIRENT       *dent;                  /* Directory entry */
   struct stat  fileinfo;               /* File information */
@@ -562,17 +513,15 @@ load_ppds(const char *d,          /* I - Actual directory */
     * No, file is new/changed, so re-scan it...
     */
 
-    if ((fp.fp = gzopen(filename, "rb")) == NULL)
+    if ((fp = cupsFileOpen(filename, "rb")) == NULL)
       continue;
 
-    fp.ptr = fp.end = NULL;
-
    /*
     * Now see if this is a PPD file...
     */
 
     line[0] = '\0';
-    ppd_gets(&fp, line, sizeof(line));
+    cupsFileGets(fp, line, sizeof(line));
 
     if (strncmp(line, "*PPD-Adobe:", 11) != 0)
     {
@@ -580,7 +529,7 @@ load_ppds(const char *d,            /* I - Actual directory */
       * Nope, close the file and continue...
       */
 
-      gzclose(fp.fp);
+      cupsFileClose(fp);
 
       continue;
     }
@@ -594,7 +543,7 @@ load_ppds(const char *d,            /* I - Actual directory */
     manufacturer[0] = '\0';
     strcpy(language, "en");
 
-    while (ppd_gets(&fp, line, sizeof(line)) != NULL)
+    while (cupsFileGets(fp, line, sizeof(line)) != NULL)
     {
       if (strncmp(line, "*Manufacturer:", 14) == 0)
        sscanf(line, "%*[^\"]\"%255[^\"]", manufacturer);
@@ -628,7 +577,7 @@ load_ppds(const char *d,            /* I - Actual directory */
     * Close the file...
     */
 
-    gzclose(fp.fp);
+    cupsFileClose(fp);
 
    /*
     * See if we got all of the required info...
@@ -832,66 +781,5 @@ load_ppds(const char *d,           /* I - Actual directory */
 
 
 /*
- * 'ppd_gets()' - Read a line from a PPD file.
- */
-
-static char *                  /* O - Line from file or NULL on EOF */
-ppd_gets(buf_t *fp,            /* I - File to read from */
-         char  *buf,           /* I - Line buffer */
-        int   buflen)          /* I - Length of buffer */
-{
-  int          ch;             /* Character from file */
-  char         *ptr,           /* Current position in line buffer */
-               *end;           /* End of line buffer */
-
- /*
-  * Range check everything...
-  */
-
-  if (fp == NULL || buf == NULL || buflen < 2)
-    return (NULL);
-
- /*
-  * Now loop until we have a valid line...
-  */
-
-  ptr = buf;
-  end = buf + buflen - 1;
-
-  for (;;)
-  {
-    if (fp->ptr >= fp->end)
-      if (buf_read(fp) <= 0)
-        break;
-
-    ch = *(fp->ptr)++;
-
-    if (ch == '\r' || ch == '\n')
-    {
-     /*
-      * Line feed or carriage return...
-      */
-
-      if (ptr == buf)          /* Skip blank lines */
-        continue;
-
-      break;
-    }
-    else if (ptr < end)
-      *ptr++ = ch;
-  }
-
-  if (ptr > buf)
-  {
-    *ptr = '\0';
-
-    return (buf);
-  }
-  else
-    return (NULL);
-}
-
-
-/*
- * End of "$Id: ppds.c,v 1.27 2002/12/17 19:00:17 swdev Exp $".
+ * End of "$Id: ppds.c,v 1.28 2003/03/30 19:50:35 mike Exp $".
  */
index e0720b7bc7587374c5d7d6f6f4884466e6c57764..d78fcf5083a3fff5a048efcd6d39214a4a871b81 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: printers.c,v 1.145 2003/03/28 17:31:23 mike Exp $"
+ * "$Id: printers.c,v 1.146 2003/03/30 19:50:35 mike Exp $"
  *
  *   Printer routines for the Common UNIX Printing System (CUPS).
  *
@@ -568,7 +568,7 @@ FreePrinterUsers(printer_t *p)      /* I - Printer */
 void
 LoadAllPrinters(void)
 {
-  FILE         *fp;                    /* printers.conf file */
+  cups_file_t  *fp;                    /* printers.conf file */
   int          linenum;                /* Current line number */
   int          len;                    /* Length of line */
   char         line[1024],             /* Line from file */
@@ -584,7 +584,7 @@ LoadAllPrinters(void)
   */
 
   snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
-  if ((fp = fopen(line, "r")) == NULL)
+  if ((fp = cupsFileOpen(line, "r")) == NULL)
   {
     LogMessage(L_ERROR, "LoadAllPrinters: Unable to open %s - %s", line,
                strerror(errno));
@@ -598,7 +598,7 @@ LoadAllPrinters(void)
   linenum = 0;
   p       = NULL;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -790,7 +790,7 @@ LoadAllPrinters(void)
     }
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -803,7 +803,7 @@ void
 SaveAllPrinters(void)
 {
   int          i;                      /* Looping var */
-  FILE         *fp;                    /* printers.conf file */
+  cups_file_t  *fp;                    /* printers.conf file */
   char         temp[1024];             /* Temporary string */
   char         backup[1024];           /* printers.conf.O file */
   printer_t    *printer;               /* Current printer class */
@@ -821,7 +821,7 @@ SaveAllPrinters(void)
   if (rename(temp, backup))
     LogMessage(L_ERROR, "Unable to backup printers.conf - %s", strerror(errno));
 
-  if ((fp = fopen(temp, "w")) == NULL)
+  if ((fp = cupsFileOpen(temp, "w")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to save printers.conf - %s", strerror(errno));
 
@@ -836,8 +836,8 @@ SaveAllPrinters(void)
   * Restrict access to the file...
   */
 
-  fchown(fileno(fp), User, Group);
-  fchmod(fileno(fp), 0600);
+  fchown(cupsFileNumber(fp), User, Group);
+  fchmod(cupsFileNumber(fp), 0600);
 
  /*
   * Write a small header to the file...
@@ -847,8 +847,8 @@ SaveAllPrinters(void)
   curdate = gmtime(&curtime);
   strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
 
-  fputs("# Printer configuration file for " CUPS_SVERSION "\n", fp);
-  fprintf(fp, "# Written by cupsd on %s\n", temp);
+  cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
+  cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
 
  /*
   * Write each local printer known to the system...
@@ -870,44 +870,44 @@ SaveAllPrinters(void)
     */
 
     if (printer == DefaultPrinter)
-      fprintf(fp, "<DefaultPrinter %s>\n", printer->name);
+      cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
     else
-      fprintf(fp, "<Printer %s>\n", printer->name);
+      cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
 
     if (printer->info)
-      fprintf(fp, "Info %s\n", printer->info);
+      cupsFilePrintf(fp, "Info %s\n", printer->info);
 
     if (printer->location)
-      fprintf(fp, "Location %s\n", printer->location);
+      cupsFilePrintf(fp, "Location %s\n", printer->location);
 
     if (printer->device_uri)
-      fprintf(fp, "DeviceURI %s\n", printer->device_uri);
+      cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
 
     if (printer->state == IPP_PRINTER_STOPPED)
     {
-      fputs("State Stopped\n", fp);
-      fprintf(fp, "StateMessage %s\n", printer->state_message);
+      cupsFilePuts(fp, "State Stopped\n");
+      cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
     }
     else
-      fputs("State Idle\n", fp);
+      cupsFilePuts(fp, "State Idle\n");
 
     if (printer->accepting)
-      fputs("Accepting Yes\n", fp);
+      cupsFilePuts(fp, "Accepting Yes\n");
     else
-      fputs("Accepting No\n", fp);
+      cupsFilePuts(fp, "Accepting No\n");
 
-    fprintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
+    cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
             printer->job_sheets[1]);
 
-    fprintf(fp, "QuotaPeriod %d\n", printer->quota_period);
-    fprintf(fp, "PageLimit %d\n", printer->page_limit);
-    fprintf(fp, "KLimit %d\n", printer->k_limit);
+    cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
+    cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
+    cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
 
     for (i = 0; i < printer->num_users; i ++)
-      fprintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
+      cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
               printer->users[i]);
 
-    fputs("</Printer>\n", fp);
+    cupsFilePuts(fp, "</Printer>\n");
 
 #ifdef __sgi
     /*
@@ -918,7 +918,7 @@ SaveAllPrinters(void)
 #endif /* __sgi */
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -1985,7 +1985,7 @@ ValidateDest(const char   *hostname,      /* I - Host name */
 void
 WritePrintcap(void)
 {
-  FILE         *fp;            /* printcap file */
+  cups_file_t  *fp;            /* printcap file */
   printer_t    *p;             /* Current printer */
 
 
@@ -2010,7 +2010,7 @@ WritePrintcap(void)
   * Open the printcap file...
   */
 
-  if ((fp = fopen(Printcap, "w")) == NULL)
+  if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
     return;
 
  /*
@@ -2018,10 +2018,10 @@ WritePrintcap(void)
   * data has come from...
   */
 
-  fputs("# This file was automatically generated by cupsd(8) from the\n", fp);
-  fprintf(fp, "# %s/printers.conf file.  All changes to this file\n",
+  cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");
+  cupsFilePrintf(fp, "# %s/printers.conf file.  All changes to this file\n",
           ServerRoot);
-  fputs("# will be lost.\n", fp);
+  cupsFilePuts(fp, "# will be lost.\n");
 
  /*
   * Write a new printcap with the current list of printers.
@@ -2041,12 +2041,12 @@ WritePrintcap(void)
        */
 
         if (DefaultPrinter)
-         fprintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
+         cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
                  DefaultPrinter->info, ServerName, DefaultPrinter->name);
 
        for (p = Printers; p != NULL; p = p->next)
          if (p != DefaultPrinter)
-           fprintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
+           cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
                    ServerName, p->name);
         break;
 
@@ -2071,15 +2071,15 @@ WritePrintcap(void)
        *            :description=Description:
        */
 
-        fputs("_all:all=", fp);
+        cupsFilePuts(fp, "_all:all=");
        for (p = Printers; p != NULL; p = p->next)
-         fprintf(fp, "%s%c", p->name, p->next ? ',' : '\n');
+         cupsFilePrintf(fp, "%s%c", p->name, p->next ? ',' : '\n');
 
         if (DefaultPrinter)
-         fprintf(fp, "_default:use=%s\n", DefaultPrinter->name);
+         cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
 
        for (p = Printers; p != NULL; p = p->next)
-         fprintf(fp, "%s:\\\n"
+         cupsFilePrintf(fp, "%s:\\\n"
                      "\t:bsdaddr=%s,%s:\\\n"
                      "\t:description=%s:\n",
                  p->name, ServerName, p->name, p->info ? p->info : "");
@@ -2090,7 +2090,7 @@ WritePrintcap(void)
   * Close the file...
   */
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -2104,7 +2104,7 @@ static void
 write_irix_config(printer_t *p)        /* I - Printer to update */
 {
   char         filename[1024]; /* Interface script filename */
-  FILE         *fp;            /* Interface script file */
+  cups_file_t  *fp;            /* Interface script file */
   ipp_attribute_t *attr;       /* Attribute value */
 
 
@@ -2118,27 +2118,27 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fputs("#!/bin/sh\n", fp);
+    cupsFilePuts(fp, "#!/bin/sh\n");
 
     if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",
                                  IPP_TAG_TEXT)) != NULL)
-      fprintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
+      cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
     else if (p->type & CUPS_PRINTER_CLASS)
-      fputs("NAME=\"Printer Class\"\n", fp);
+      cupsFilePuts(fp, "NAME=\"Printer Class\"\n");
     else
-      fputs("NAME=\"Remote Destination\"\n", fp);
+      cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
 
     if (p->type & CUPS_PRINTER_COLOR)
-      fputs("TYPE=ColorPostScript\n", fp);
+      cupsFilePuts(fp, "TYPE=ColorPostScript\n");
     else
-      fputs("TYPE=MonoPostScript\n", fp);
+      cupsFilePuts(fp, "TYPE=MonoPostScript\n");
 
-    fprintf(fp, "HOSTNAME=%s\n", ServerName);
-    fprintf(fp, "HOSTPRINTER=%s\n", p->name);
+    cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
+    cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0755);
     chown(filename, User, Group);
@@ -2154,11 +2154,11 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fputs("/dev/null\n", fp);
+    cupsFilePuts(fp, "/dev/null\n");
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0644);
     chown(filename, User, Group);
@@ -2180,12 +2180,12 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fputs("#!/bin/sh\n", fp);
-    fprintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
+    cupsFilePuts(fp, "#!/bin/sh\n");
+    cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0755);
     chown(filename, User, Group);
@@ -2200,19 +2200,19 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fprintf(fp, "Printer Class      | %s\n",
+    cupsFilePrintf(fp, "Printer Class      | %s\n",
             (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
-    fprintf(fp, "Printer Model      | %s\n", p->make_model ? p->make_model : "");
-    fprintf(fp, "Location Code      | %s\n", p->location ? p->location : "");
-    fprintf(fp, "Physical Location  | %s\n", p->info ? p->info : "");
-    fprintf(fp, "Port Path          | %s\n", p->device_uri ? p->device_uri : "");
-    fprintf(fp, "Config Path        | /var/spool/lp/pod/%s.config\n", p->name);
-    fprintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
-    fputs("Status Update Wait | 10 seconds\n", fp);
+    cupsFilePrintf(fp, "Printer Model      | %s\n", p->make_model ? p->make_model : "");
+    cupsFilePrintf(fp, "Location Code      | %s\n", p->location ? p->location : "");
+    cupsFilePrintf(fp, "Physical Location  | %s\n", p->info ? p->info : "");
+    cupsFilePrintf(fp, "Port Path          | %s\n", p->device_uri ? p->device_uri : "");
+    cupsFilePrintf(fp, "Config Path        | /var/spool/lp/pod/%s.config\n", p->name);
+    cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
+    cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0664);
     chown(filename, User, Group);
@@ -2226,11 +2226,11 @@ write_irix_config(printer_t *p) /* I - Printer to update */
  */
 
 static void
-write_irix_state(printer_t *p) /* I - Printer to update */
+write_irix_state(printer_t *p)         /* I - Printer to update */
 {
-  char filename[1024];         /* Interface script filename */
-  FILE *fp;                    /* Interface script file */
-  int  tag;                    /* Status tag value */
+  char         filename[1024];         /* Interface script filename */
+  cups_file_t  *fp;                    /* Interface script file */
+  int          tag;                    /* Status tag value */
 
 
   if (p)
@@ -2244,20 +2244,20 @@ write_irix_state(printer_t *p)  /* I - Printer to update */
 
     if (p->type & CUPS_PRINTER_CLASS)
       unlink(filename);
-    else if ((fp = fopen(filename, "w")) != NULL)
+    else if ((fp = cupsFileOpen(filename, "w")) != NULL)
     {
-      fprintf(fp, "Operational Status | %s\n",
+      cupsFilePrintf(fp, "Operational Status | %s\n",
               (p->state == IPP_PRINTER_IDLE)       ? "Idle" :
               (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
                                                      "Faulted");
-      fprintf(fp, "Information        | 01 00 00 | %s\n", CUPS_SVERSION);
-      fprintf(fp, "Information        | 02 00 00 | Device URI: %s\n",
+      cupsFilePrintf(fp, "Information        | 01 00 00 | %s\n", CUPS_SVERSION);
+      cupsFilePrintf(fp, "Information        | 02 00 00 | Device URI: %s\n",
               p->device_uri ? p->device_uri : "");
-      fprintf(fp, "Information        | 03 00 00 | %s jobs\n",
+      cupsFilePrintf(fp, "Information        | 03 00 00 | %s jobs\n",
               p->accepting ? "Accepting" : "Not accepting");
-      fprintf(fp, "Information        | 04 00 00 | %s\n", p->state_message);
+      cupsFilePrintf(fp, "Information        | 04 00 00 | %s\n", p->state_message);
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       chmod(filename, 0664);
       chown(filename, User, Group);
@@ -2298,7 +2298,7 @@ write_irix_state(printer_t *p)    /* I - Printer to update */
 
     if (p->type & CUPS_PRINTER_CLASS)
       unlink(filename);
-    else if ((fp = fopen(filename, "w")) != NULL)
+    else if ((fp = cupsFileOpen(filename, "w")) != NULL)
     {
       if (p->type & CUPS_PRINTER_COLOR)
        tag = 66240;
@@ -2314,10 +2314,10 @@ write_irix_state(printer_t *p)  /* I - Printer to update */
       else if (p->state == IPP_PRINTER_STOPPED)
        tag |= 2;
 
-      fputs("#!/bin/sh\n", fp);
-      fprintf(fp, "#Tag %d\n", tag);
+      cupsFilePuts(fp, "#!/bin/sh\n");
+      cupsFilePrintf(fp, "#Tag %d\n", tag);
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       chmod(filename, 0755);
       chown(filename, User, Group);
@@ -2333,11 +2333,11 @@ write_irix_state(printer_t *p)  /* I - Printer to update */
 
   if (DefaultPrinter != NULL)
   {
-    if ((fp = fopen(filename, "w")) != NULL)
+    if ((fp = cupsFileOpen(filename, "w")) != NULL)
     {
-      fprintf(fp, "%s\n", DefaultPrinter->name);
+      cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       chmod(filename, 0644);
       chown(filename, User, Group);
@@ -2350,5 +2350,5 @@ write_irix_state(printer_t *p)    /* I - Printer to update */
 
 
 /*
- * End of "$Id: printers.c,v 1.145 2003/03/28 17:31:23 mike Exp $".
+ * End of "$Id: printers.c,v 1.146 2003/03/30 19:50:35 mike Exp $".
  */
index 5c0b5ec310b782df4004db9c67526b3c9be24381..3d0a61fccf8fb1241755e4381289bc7ec4bf9a2c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: server.c,v 1.12 2003/03/28 22:28:00 mike Exp $"
+ * "$Id: server.c,v 1.13 2003/03/30 19:50:35 mike Exp $"
  *
  *   Server start/stop routines for the Common UNIX Printing System (CUPS).
  *
@@ -141,21 +141,21 @@ StopServer(void)
 
   if (AccessFile != NULL)
   {
-    fclose(AccessFile);
+    cupsFileClose(AccessFile);
 
     AccessFile = NULL;
   }
 
   if (ErrorFile != NULL)
   {
-    fclose(ErrorFile);
+    cupsFileClose(ErrorFile);
 
     ErrorFile = NULL;
   }
 
   if (PageFile != NULL)
   {
-    fclose(PageFile);
+    cupsFileClose(PageFile);
 
     PageFile = NULL;
   }
@@ -170,5 +170,5 @@ StopServer(void)
 
 
 /*
- * End of "$Id: server.c,v 1.12 2003/03/28 22:28:00 mike Exp $".
+ * End of "$Id: server.c,v 1.13 2003/03/30 19:50:35 mike Exp $".
  */