tempnam.c (22993) | tempnam.c (50121) |
---|---|
1/* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) 35#if 0 36static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93"; 37#endif 38static const char rcsid[] = | 1/* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) 35#if 0 36static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93"; 37#endif 38static const char rcsid[] = |
39 "$Id$"; | 39 "$Id: tempnam.c,v 1.5 1997/02/22 15:02:37 peter Exp $"; |
40#endif /* LIBC_SCCS and not lint */ 41 42#include <sys/param.h> 43#include <errno.h> 44#include <stdio.h> 45#include <stdlib.h> 46#include <string.h> 47#include <unistd.h> 48#include <paths.h> 49 | 40#endif /* LIBC_SCCS and not lint */ 41 42#include <sys/param.h> 43#include <errno.h> 44#include <stdio.h> 45#include <stdlib.h> 46#include <string.h> 47#include <unistd.h> 48#include <paths.h> 49 |
50__warn_references(tempnam, 51 "warning: tempnam() possibly used unsafely; consider using mkstemp()"); 52 53extern char *_mktemp __P((char *)); 54 |
|
50char * 51tempnam(dir, pfx) 52 const char *dir, *pfx; 53{ 54 int sverrno; 55 char *f, *name; 56 57 if (!(name = malloc(MAXPATHLEN))) 58 return(NULL); 59 60 if (!pfx) 61 pfx = "tmp."; 62 | 55char * 56tempnam(dir, pfx) 57 const char *dir, *pfx; 58{ 59 int sverrno; 60 char *f, *name; 61 62 if (!(name = malloc(MAXPATHLEN))) 63 return(NULL); 64 65 if (!pfx) 66 pfx = "tmp."; 67 |
63 if ((f = getenv("TMPDIR"))) { | 68 if (issetugid() == 0 && (f = getenv("TMPDIR"))) { |
64 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, 65 *(f + strlen(f) - 1) == '/'? "": "/", pfx); | 69 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, 70 *(f + strlen(f) - 1) == '/'? "": "/", pfx); |
66 if ((f = mktemp(name))) | 71 if ((f = _mktemp(name))) |
67 return(f); 68 } 69 70 if ((f = (char *)dir)) { 71 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, 72 *(f + strlen(f) - 1) == '/'? "": "/", pfx); 73 if ((f = mktemp(name))) 74 return(f); --- 17 unchanged lines hidden --- | 72 return(f); 73 } 74 75 if ((f = (char *)dir)) { 76 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, 77 *(f + strlen(f) - 1) == '/'? "": "/", pfx); 78 if ((f = mktemp(name))) 79 return(f); --- 17 unchanged lines hidden --- |