mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-28 05:20:28 +00:00
Remove hints from Windows imports
This commit is contained in:
parent
7e0a09feec
commit
83341a4269
2449 changed files with 7093 additions and 7048 deletions
|
@ -32,6 +32,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
|
@ -282,6 +283,24 @@ static int Cat(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int Mktemp(void) {
|
||||
int fd;
|
||||
char template[PATH_MAX + 1];
|
||||
if (n == 2) {
|
||||
strlcpy(template, args[1], sizeof(template));
|
||||
} else {
|
||||
strlcpy(template, kTmpPath, sizeof(template));
|
||||
strlcat(template, "tmp.XXXXXX", sizeof(template));
|
||||
}
|
||||
if ((fd = mkstemp(template)) == -1) {
|
||||
perror("mkstemp");
|
||||
return 1;
|
||||
}
|
||||
Write(1, template);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Read(void) {
|
||||
unsigned char c;
|
||||
int i, j, rc = 1;
|
||||
|
@ -583,6 +602,7 @@ static int TryBuiltin(void) {
|
|||
if (!strcmp(args[0], "rmdir")) return Rmdir();
|
||||
if (!strcmp(args[0], "mkdir")) return Mkdir();
|
||||
if (!strcmp(args[0], "false")) return False();
|
||||
if (!strcmp(args[0], "mktemp")) return Mktemp();
|
||||
if (!strcmp(args[0], "usleep")) return Usleep();
|
||||
if (!strcmp(args[0], "toupper")) return Toupper();
|
||||
if (_weaken(_tr) && !strcmp(args[0], "tr")) return Fake(_weaken(_tr));
|
||||
|
|
54
libc/runtime/mkstemp.c
Normal file
54
libc/runtime/mkstemp.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Creates temporary file name and descriptor, e.g.
|
||||
*
|
||||
* char path[PATH_MAX+1];
|
||||
* strlcat(path, kTmpDir, sizeof(path));
|
||||
* strlcat(path, "sauce.XXXXXX", sizeof(path));
|
||||
* close(mkstemp(path));
|
||||
* puts(path);
|
||||
*
|
||||
* @param template is mutated to replace last six X's with rng
|
||||
* @return open file descriptor r + w exclusive or -1 w/ errno
|
||||
* @raise EINVAL if `template` didn't end with `XXXXXX`
|
||||
*/
|
||||
int mkstemp(char *template) {
|
||||
int i, n;
|
||||
uint64_t w;
|
||||
if ((n = strlen(template)) < 6 ||
|
||||
READ16LE(template + n - 2) != READ16LE("XX") ||
|
||||
READ32LE(template + n - 6) != READ32LE("XXXX")) {
|
||||
return einval();
|
||||
}
|
||||
w = _rand64();
|
||||
for (i = 0; i < 6; ++i) {
|
||||
template[n - 6 + i] = "0123456789abcdefghijklmnopqrstuvwxyz"[w % 36];
|
||||
w /= 36;
|
||||
}
|
||||
return open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue