fdcreate/fdcreate.c

25 lines
479 B
C
Raw Permalink Normal View History

2022-08-11 10:32:36 +00:00
#include <sys/mman.h>
#include <stdlib.h>
2022-08-12 00:37:57 +00:00
#include <skalibs/types.h>
2022-08-11 10:32:36 +00:00
#include <skalibs/strerr2.h>
#include <skalibs/env.h>
#include <skalibs/exec.h>
#define USAGE "fdcreate name prog..."
int main(int argc, char const *const *argv) {
PROG = "fdcreate";
2022-08-12 00:37:57 +00:00
char fd_str[10];
2022-08-11 10:32:36 +00:00
if (argc < 3) strerr_dieusage(100, USAGE);
int fd = memfd_create(argv[1], 0);
if (fd < 0) strerr_diefu1sys(111, "memfd_create");
2022-08-12 00:37:57 +00:00
int_fmt(fd_str, fd);
2022-08-11 10:32:36 +00:00
setenv(argv[1], fd_str, 1);
xexec(argv+2);
}