mirror of
https://github.com/fumiama/CMoe-Counter.git
synced 2024-11-27 15:20:47 +01:00
add funlock
This commit is contained in:
parent
946cbbac67
commit
5b380eec53
13
cmoe.c
13
cmoe.c
@ -139,7 +139,7 @@ static void return_count(FILE* fp, char* name, char* theme) {
|
||||
h = H_SMALL;
|
||||
head = (char*)svg_small;
|
||||
}
|
||||
if(headers(get_content_len(isbig, len_type, cntstr), image/svg+xml)) {
|
||||
if(headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml")) {
|
||||
write(1, "\0\0\0\0", 4);
|
||||
return;
|
||||
}
|
||||
@ -210,6 +210,7 @@ int main(int argc, char **argv) {
|
||||
return -3;
|
||||
}
|
||||
return_count(fp, name, theme);
|
||||
flock(fileno(fp), LOCK_UN);
|
||||
fclose(fp); fp = NULL;
|
||||
return 0;
|
||||
}
|
||||
@ -231,10 +232,12 @@ int main(int argc, char **argv) {
|
||||
return -5;
|
||||
}
|
||||
if(name_exist(fp, name)) {
|
||||
flock(fileno(fp), LOCK_UN);
|
||||
fclose(fp); fp = NULL;
|
||||
http_error(HTTP400, "Name Exist.");
|
||||
return 7;
|
||||
}
|
||||
flock(fileno(fp), LOCK_UN);
|
||||
fclose(fp); fp = NULL;
|
||||
fp = fopen(datfile, "ab+");
|
||||
if (!fp) {
|
||||
@ -246,9 +249,10 @@ int main(int argc, char **argv) {
|
||||
return -7;
|
||||
}
|
||||
add_user(name, 0, fp);
|
||||
flock(fileno(fp), LOCK_UN);
|
||||
fclose(fp); fp = NULL;
|
||||
char* msg = "<P>Success.\r\n";
|
||||
if(headers(strlen(msg), text/html)) {
|
||||
if(headers(strlen(msg), "text/html")) {
|
||||
write(1, "\0\0\0\0", 4);
|
||||
return 8;
|
||||
}
|
||||
@ -256,5 +260,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) defer_close_fp() {
|
||||
if(fp) fclose(fp);
|
||||
if(fp) {
|
||||
flock(fileno(fp), LOCK_UN);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
2
cmoe.h
2
cmoe.h
@ -21,7 +21,7 @@ const uint8_t typel[] = {59, 111, 69};
|
||||
enum errcode_enum_t {HTTP400, HTTP404, HTTP500};
|
||||
typedef enum errcode_enum_t errcode_enum_t;
|
||||
|
||||
#define CONTENT_TYPE(x) "Content-Type: " #x "\r\n"
|
||||
#define CONTENT_TYPE(x) "Content-Type: " x "\r\n"
|
||||
#define CONTENT_LEN "Content-Length: %d\r\n"
|
||||
#define CACHE_CTRL "Cache-Control: max-age=0, no-cache, no-store, must-revalidate\r\n"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user