source: trunk/minix/lib/stdio/tmpnam.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 732 bytes
Line 
1/*
2 * tmpnam.c - create a unique filename
3 */
4/* $Header: /cvsup/minix/src/lib/stdio/tmpnam.c,v 1.1.1.1 2005/04/21 14:56:36 beng Exp $ */
5
6#if defined(_POSIX_SOURCE)
7#include <sys/types.h>
8#endif
9#include <stdio.h>
10#include <string.h>
11#include "loc_incl.h"
12
13pid_t _getpid(void);
14
15char *
16tmpnam(char *s) {
17 static char name_buffer[L_tmpnam] = "/tmp/tmp.";
18 static unsigned long count = 0;
19 static char *name = NULL;
20
21 if (!name) {
22 name = name_buffer + strlen(name_buffer);
23 name = _i_compute((unsigned long)_getpid(), 10, name, 5);
24 *name++ = '.';
25 *name = '\0';
26 }
27 if (++count > TMP_MAX) count = 1; /* wrap-around */
28 *_i_compute(count, 10, name, 3) = '\0';
29 if (s) return strcpy(s, name_buffer);
30 else return name_buffer;
31}
Note: See TracBrowser for help on using the repository browser.