]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/util.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / scheduler / util.c
index c876c9a045378cc7cc18a75f1853d590fba17dc4..19ebf069bcc8db50a0882cfa91cf8abd4688d446 100644 (file)
@@ -1,27 +1,14 @@
 /*
- * "$Id: util.c 7621 2008-06-06 18:55:35Z mike $"
+ * Mini-daemon utility functions for CUPS.
  *
- *   Mini-daemon utility functions for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2005 by Easy Software Products.
  *
- *   Copyright 2007-2008 by Apple Inc.
- *   Copyright 1997-2005 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- *   cupsdCompareNames()   - Compare two names.
- *   cupsdExec()           - Run a program with the correct environment.
- *   cupsdPipeCommand()    - Read output from a command.
- *   cupsdSendIPPGroup()   - Send a group tag.
- *   cupsdSendIPPHeader()  - Send the IPP response header.
- *   cupsdSendIPPInteger() - Send an integer attribute.
- *   cupsdSendIPPString()  - Send a string attribute.
- *   cupsdSendIPPTrailer() - Send the end-of-message tag.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * missing or damaged, see the license at "http://www.cups.org/".
  */
 
 /*
 #ifdef __APPLE__
 #  include <libgen.h>
 extern char **environ;
-#endif /* __APPLE__ */ 
+#endif /* __APPLE__ */
 
 
 /*
  * 'cupsdCompareNames()' - Compare two names.
  *
- * This function basically does a strcasecmp() of the two strings,
+ * This function basically does a _cups_strcasecmp() of the two strings,
  * but is also aware of numbers so that "a2" < "a100".
  */
 
@@ -90,7 +77,7 @@ cupsdCompareNames(const char *s,      /* I - First string */
       else if (!isdigit(*s & 255) && isdigit(*t & 255))
         return (-1);
       else if (!isdigit(*s & 255) || !isdigit(*t & 255))
-        continue;     
+        continue;
 
       if (*s < *t)
         diff = -1;
@@ -152,10 +139,24 @@ cupsdCompareNames(const char *s,  /* I - First string */
 }
 
 
+/*
+ * 'cupsdCreateStringsArray()' - Create a CUPS array of strings.
+ */
+
+cups_array_t *                         /* O - CUPS array */
+cupsdCreateStringsArray(const char *s) /* I - Comma-delimited strings */
+{
+  if (!s || !*s)
+    return (NULL);
+  else
+    return (_cupsArrayNewStrings(s, ','));
+}
+
+
 /*
  * 'cupsdExec()' - Run a program with the correct environment.
  *
- * On Mac OS X, we need to update the CFProcessPath environment variable that
+ * On macOS, we need to update the CFProcessPath environment variable that
  * is passed in the environment so the child can access its bundled resources.
  */
 
@@ -172,7 +173,7 @@ cupsdExec(const char *command,              /* I - Full path to program */
 
 
  /*
-  * Some Mac OS X programs are bundled and need the CFProcessPath environment
+  * Some macOS programs are bundled and need the CFProcessPath environment
   * variable defined.  If the command is a symlink, resolve the link and point
   * to the resolved location, otherwise, use the command path itself.
   */
@@ -236,9 +237,10 @@ cups_file_t *                              /* O - CUPS file or NULL on error */
 cupsdPipeCommand(int        *pid,      /* O - Process ID or 0 on error */
                  const char *command,  /* I - Command to run */
                  char       **argv,    /* I - Arguments to pass to command */
-                int        user)       /* I - User to run as or 0 for current */
+                uid_t      user)       /* I - User to run as or 0 for current */
 {
-  int  fds[2];                         /* Pipe file descriptors */
+  int  fd,                             /* Temporary file descriptor */
+       fds[2];                         /* Pipe file descriptors */
 
 
  /*
@@ -300,11 +302,14 @@ cupsdPipeCommand(int        *pid, /* O - Process ID or 0 on error */
     if (!getuid() && user)
       setuid(user);                    /* Run as restricted user */
 
-    close(0);                          /* </dev/null */
-    open("/dev/null", O_RDONLY);
+    if ((fd = open("/dev/null", O_RDONLY)) > 0)
+    {
+      dup2(fd, 0);                     /* </dev/null */
+      close(fd);
+    }
 
-    close(1);                          /* >pipe */
-    dup(fds[1]);
+    dup2(fds[1], 1);                   /* >pipe */
+    close(fds[1]);
 
     cupsdExec(command, argv);
     exit(errno);
@@ -347,6 +352,8 @@ cupsdSendIPPHeader(
  /*
   * Send IPP/1.1 response header: version number (2 bytes), status code
   * (2 bytes), and request ID (4 bytes)...
+  *
+  * TODO: Add version number (IPP/2.x and IPP/1.0) support.
   */
 
   putchar(1);
@@ -383,8 +390,8 @@ cupsdSendIPPInteger(
   putchar(value_tag);
 
   len = strlen(name);
-  putchar(len >> 8);
-  putchar(len);
+  putchar((int)(len >> 8));
+  putchar((int)len);
 
   fputs(name, stdout);
 
@@ -420,14 +427,14 @@ cupsdSendIPPString(
   putchar(value_tag);
 
   len = strlen(name);
-  putchar(len >> 8);
-  putchar(len);
+  putchar((int)(len >> 8));
+  putchar((int)len);
 
   fputs(name, stdout);
 
   len = strlen(value);
-  putchar(len >> 8);
-  putchar(len);
+  putchar((int)(len >> 8));
+  putchar((int)len);
 
   fputs(value, stdout);
 }
@@ -443,8 +450,3 @@ cupsdSendIPPTrailer(void)
   putchar(IPP_TAG_END);
   fflush(stdout);
 }
-
-
-/*
- * End of "$Id: util.c 7621 2008-06-06 18:55:35Z mike $".
- */