/[man-db]/man-db/lib/tempfile.c
ViewVC logotype

Diff of /man-db/lib/tempfile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by cjwatson, Mon Mar 10 15:05:29 2003 UTC revision 1.8 by cjwatson, Thu May 1 15:54:03 2003 UTC
# Line 37  Line 37 
37    
38  /* Other library functions used in man-db. */  /* Other library functions used in man-db. */
39  extern char *strappend (char *str, ...);  extern char *strappend (char *str, ...);
40  extern char *xstrdup (char *string);  extern char *xstrdup (const char *string);
41  extern int mkstemp (char *template);  extern int mkstemp (char *template);
42  extern char *mkdtemp (char *template);  extern char *mkdtemp (char *template);
43    
44  static char *path_search ()  static const char *path_search ()
45  {  {
46          char *dir = NULL;          const char *dir = NULL;
47    
48          if (getuid () == geteuid () && getgid () == getegid ()) {          if (getuid () == geteuid () && getgid () == getegid ()) {
49                  dir = getenv ("TMPDIR");                  dir = getenv ("TMPDIR");
# Line 76  static char *path_search () Line 76  static char *path_search ()
76   */   */
77  int create_tempfile (const char *template, char **created_filename)  int create_tempfile (const char *template, char **created_filename)
78  {  {
79          char *dir = path_search ();          char *dir = xstrdup (path_search ());
80          int fd;          int fd;
81          mode_t old_mode;          mode_t old_mode;
82    
83          if (!dir)          if (!dir)
84                  return -1;                  return -1;
         dir = xstrdup (dir);  
85          *created_filename = strappend (dir, "/", template, "XXXXXX", NULL);          *created_filename = strappend (dir, "/", template, "XXXXXX", NULL);
86          /* -rw------- */          /* -rw------- */
87          old_mode = umask (S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);          old_mode = umask (S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
# Line 96  int create_tempfile (const char *templat Line 95  int create_tempfile (const char *templat
95   */   */
96  char *create_tempdir (const char *template)  char *create_tempdir (const char *template)
97  {  {
98          char *dir = path_search ();          char *dir = xstrdup (path_search ());
99          char *created_dirname;          char *created_dirname;
100    
101          if (!dir)          if (!dir)
102                  return NULL;                  return NULL;
         dir = xstrdup (dir);  
103          created_dirname = strappend (dir, "/", template, "XXXXXX", NULL);          created_dirname = strappend (dir, "/", template, "XXXXXX", NULL);
104          mkdtemp (created_dirname);          mkdtemp (created_dirname);
105          return created_dirname;          return created_dirname;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26