ReactOS  0.4.15-dev-499-g1f31905
port.h File Reference
#include "getopt_int.h"
Include dependency graph for port.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int mkstemps (char *template, int suffix_len)
 

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  {
108  gcc_uint64_t v = value;
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 }
#define TMP_MAX
Definition: mkstemps.c:43
#define open
Definition: acwin.h:95
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint GLuint GLsizei count
Definition: gl.h:1545
static int fd
Definition: io.c:51
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
smooth NULL
Definition: ftsmooth.c:416
#define O_EXCL
Definition: fcntl.h:40
_CRTIMP int __cdecl getpid(void)
unsigned long gcc_uint64_t
Definition: mkstemps.c:39
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
GLenum GLsizei len
Definition: glext.h:6722
GLsizei const GLfloat * value
Definition: glext.h:6069
const GLdouble * v
Definition: gl.h:2040
#define O_RDWR
Definition: fcntl.h:36
#define O_BINARY
Definition: mkstemps.c:48
#define O_CREAT
Definition: acwin.h:110
#define printf
Definition: config.h:203