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: 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 |
50__warn_references(tempnam, 51 "warning: tempnam() possibly used unsafely; consider using mkstemp()"); 52 53extern char *_mktemp __P((char *)); 54 |
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 |
68 if (issetugid() == 0 && (f = getenv("TMPDIR"))) { |
69 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, 70 *(f + strlen(f) - 1) == '/'? "": "/", pfx); |
71 if ((f = _mktemp(name))) |
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 --- |