entropy/util/gen_constants.c
2020-12-04 15:20:52 -07:00

40 lines
1.3 KiB
C

/* gen_constanc.c: this simple programe writes `constants_linux.go` based on available headers.
*
* Author: J. Lowell Wofford <lowell@lanl.gov>
*
* This software is open source software available under the BSD-3 license.
* Copyright (c) 2020, J. Lowell Wofford.
* See LICENSE file for details.
*/
#include <fcntl.h>
#include <linux/random.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
const char * filename = "constants_linux.go";
int main() {
int fd;
printf("Generating constants for entropy IOCTLs.\n");
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if( fd == -1 ) {
printf("Failed to open output file: %s\n", filename);
return -1;
}
dprintf(fd, "// generated by gen_constants.c\n\n");
dprintf(fd, "package entropy\n\n");
dprintf(fd, "const (\n");
dprintf(fd, "\tRNDGETENTCNT = %#x\n", RNDGETENTCNT);
dprintf(fd, "\tRNDADDTOENTCNT = %#x\n", RNDADDTOENTCNT);
dprintf(fd, "\tRNDGETPOOL = %#x\n", RNDGETPOOL);
dprintf(fd, "\tRNDADDENTROPY = %#x\n", RNDADDENTROPY);
dprintf(fd, "\tRNDZAPENTCNT = %#x\n", RNDZAPENTCNT);
dprintf(fd, "\tRNDCLEARPOOL = %#x\n", RNDCLEARPOOL);
dprintf(fd, "\tRNDRESEEDCRNG = %#x\n", RNDRESEEDCRNG);
dprintf(fd, ")\n\n");
close(fd);
return 0;
}