ReactOS 0.4.16-dev-257-g6aa11ac
mkstemps.c File Reference
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
Include dependency graph for mkstemps.c:

Go to the source code of this file.

Macros

#define TMP_MAX   16384
 
#define O_BINARY   0
 

Typedefs

typedef unsigned long gcc_uint64_t
 

Functions

int mkstemps (char *template, int suffix_len)
 

Macro Definition Documentation

◆ O_BINARY

#define O_BINARY   0

Definition at line 48 of file mkstemps.c.

◆ TMP_MAX

#define TMP_MAX   16384

Definition at line 43 of file mkstemps.c.

Typedef Documentation

◆ gcc_uint64_t

Definition at line 39 of file mkstemps.c.

Function Documentation

◆ mkstemps()

int mkstemps ( char template,
int  suffix_len 
)

Definition at line 73 of file mkstemps.c.

76{
77 static const char letters[]
78 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
79 static gcc_uint64_t value;
80#ifdef HAVE_GETTIMEOFDAY
81 struct timeval tv;
82#endif
83 char *XXXXXX;
84 size_t len;
85 int count;
86
87 len = strlen (template);
88
89 if ((int) len < 6 + suffix_len
90 || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6))
91 {
92 printf("wrong parameter\n");
93 return -1;
94 }
95
96 XXXXXX = &template[len - 6 - suffix_len];
97
98#ifdef HAVE_GETTIMEOFDAY
99 /* Get some more or less random data. */
100 gettimeofday (&tv, NULL);
101 value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
102#else
103 value += getpid ();
104#endif
105
106 for (count = 0; count < TMP_MAX; ++count)
107 {
109 int fd;
110
111 /* Fill in the random bits. */
112 XXXXXX[0] = letters[v % 62];
113 v /= 62;
114 XXXXXX[1] = letters[v % 62];
115 v /= 62;
116 XXXXXX[2] = letters[v % 62];
117 v /= 62;
118 XXXXXX[3] = letters[v % 62];
119 v /= 62;
120 XXXXXX[4] = letters[v % 62];
121 v /= 62;
122 XXXXXX[5] = letters[v % 62];
123
124#ifdef VMS
125 fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600, "fop=tmd");
126#else
127 fd = open (template, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600);
128#endif
129 if (fd >= 0)
130 /* The file does not exist. */
131 return fd;
132
133 /* This is a random value. It is only necessary that the next
134 TMP_MAX values generated by adding 7777 to VALUE are different
135 with (module 2^32). */
136 value += 7777;
137 }
138
139 /* We return the null string if we can't find a unique file name. */
140 template[0] = '\0';
141 return -1;
142}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define O_CREAT
Definition: acwin.h:110
#define open
Definition: acwin.h:95
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
#define NULL
Definition: types.h:112
#define printf
Definition: freeldr.h:97
const GLdouble * v
Definition: gl.h:2040
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLsizei len
Definition: glext.h:6722
#define O_EXCL
Definition: fcntl.h:40
#define O_RDWR
Definition: fcntl.h:36
#define O_BINARY
Definition: mkstemps.c:48
unsigned long gcc_uint64_t
Definition: mkstemps.c:39
#define TMP_MAX
Definition: mkstemps.c:43
static int fd
Definition: io.c:51
Definition: pdh_main.c:94
#define getpid
Definition: wintirpc.h:52

Referenced by chmc_section_create(), and main().