Changes in uspace/lib/posix/src/stdlib.c [75c430e3:4e6a610] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/src/stdlib.c
r75c430e3 r4e6a610 38 38 39 39 #include <errno.h> 40 #include <tmpfile.h> 40 41 41 42 #include "posix/fcntl.h" … … 49 50 #include "libc/vfs/vfs.h" 50 51 #include "libc/stats.h" 51 52 /**53 * Integer absolute value.54 *55 * @param i Input value.56 * @return Absolute value of the parameter.57 */58 int abs(int i)59 {60 return i < 0 ? -i : i;61 }62 63 /**64 * Long integer absolute value.65 *66 * @param i Input value.67 * @return Absolute value of the parameter.68 */69 long labs(long i)70 {71 return i < 0 ? -i : i;72 }73 74 /**75 * Long long integer absolute value.76 *77 * @param i Input value.78 * @return Absolute value of the parameter.79 */80 long long llabs(long long i)81 {82 return i < 0 ? -i : i;83 }84 52 85 53 /** … … 196 164 int mkstemp(char *tmpl) 197 165 { 198 int fd = -1; 199 200 char *tptr = tmpl + strlen(tmpl) - 6; 201 202 while (fd < 0) { 203 if (*mktemp(tmpl) == '\0') { 204 /* Errno set by mktemp(). */ 205 return -1; 206 } 207 208 fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); 209 210 if (fd == -1) { 211 /* Restore template to it's original state. */ 212 snprintf(tptr, 7, "XXXXXX"); 213 } 214 } 215 216 return fd; 166 int tmpl_len; 167 int file; 168 169 tmpl_len = strlen(tmpl); 170 if (tmpl_len < 6) { 171 errno = EINVAL; 172 return -1; 173 } 174 175 char *tptr = tmpl + tmpl_len - 6; 176 if (strcmp(tptr, "XXXXXX") != 0) { 177 errno = EINVAL; 178 return -1; 179 } 180 181 file = __tmpfile_templ(tmpl, true); 182 if (file < 0) { 183 errno = EIO; // XXX could be more specific 184 return -1; 185 } 186 187 return file; 217 188 } 218 189 … … 227 198 char *mktemp(char *tmpl) 228 199 { 229 int tmpl_len = strlen(tmpl); 200 int tmpl_len; 201 int rc; 202 203 tmpl_len = strlen(tmpl); 230 204 if (tmpl_len < 6) { 231 205 errno = EINVAL; … … 241 215 } 242 216 243 static int seq = 0; 244 245 for (; seq < 1000000; ++seq) { 246 snprintf(tptr, 7, "%06d", seq); 247 248 int orig_errno = errno; 249 errno = 0; 250 /* Check if the file exists. */ 251 if (access(tmpl, F_OK) == -1) { 252 if (errno == ENOENT) { 253 errno = orig_errno; 254 break; 255 } else { 256 /* errno set by access() */ 257 *tmpl = '\0'; 258 return tmpl; 259 } 260 } 261 } 262 263 if (seq == 10000000) { 264 errno = EEXIST; 217 rc = __tmpfile_templ(tmpl, false); 218 if (rc != 0) { 219 errno = EIO; // XXX could be more specific 265 220 *tmpl = '\0'; 266 221 return tmpl;
Note:
See TracChangeset
for help on using the changeset viewer.