Created
August 11, 2020 00:54
-
-
Save databoose/799126d9431136b2581385e4e1e9e89d to your computer and use it in GitHub Desktop.
option snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef enum { | |
create, | |
update | |
} THREAD_STORE_OPTION; | |
void thread_store(THREAD_STORE_OPTION opt) { | |
FILE *fptr; | |
if (opt == create) { | |
if(access("/dev/shm/linkup-varstore/thread_count", F_OK) != -1) { // if file doesn't exist | |
if(system("mkdir /dev/shm/linkup-varstore") <= -1) { | |
printf("possible system() error : %s (Error code %d)\n", strerror(errno), errno); | |
errno = 0; // keeping errno fresh incase current function didn't call it | |
} | |
} | |
} | |
if (opt == update) { | |
remove("/dev/shm/linkup-varstore/thread_count"); | |
if(system(appendcmd) <= -1) { //update file with new value | |
printf("possible system() error : %s (Error code %d)\n", strerror(errno), errno); | |
errno = 0; // keeping errno fresh incase current function didn't call it | |
} | |
fptr = fopen ("/dev/shm/linkup-varstore/thread_count", "r"); | |
while (!feof (fptr)) | |
{ | |
if(fscanf(fptr,"%d",&thread_count) == 0) { | |
printf("possible fscaf error : %s (Error code %d)\n", strerror(errno), errno); | |
errno = 0; | |
} | |
} | |
fclose (fptr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment