tests: Portability fixes, replaced 0/1/-1 return codes with macros

This commit is contained in:
Tibor Nagy
2019-02-20 20:20:07 +01:00
parent ff874c87d7
commit c19cc8b731
76 changed files with 178 additions and 133 deletions
+1 -1
View File
@@ -9,5 +9,5 @@ int main(void) {
printf("%s\n", fgets(in, 30, f));
setvbuf(stdout, 0, _IONBF, 0);
printf("Hello\n");
return 0;
return EXIT_SUCCESS;
}
+2 -1
View File
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
//FILE *f = fopen("/etc/ssl/certs/ca-certificates.crt", "r");
@@ -12,7 +13,7 @@ int main(void) {
puts("EOF");
if (!feof(f)) {
puts("feof() not updated!");
return -1;
return EXIT_FAILURE;
}
break;
}
+1 -1
View File
@@ -7,5 +7,5 @@ int main(void) {
char *in = "Hello World!";
fputs(in, f); // calls fwrite, helpers::fwritex, internal::to_write and internal::stdio_write
fclose(f);
return 0;
return EXIT_SUCCESS;
}
+3 -2
View File
@@ -1,5 +1,6 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *fp = fopen("stdio/fread.in", "rb");
@@ -8,7 +9,7 @@ int main(void) {
for (int i = 1; i <= 32; ++i) {
if (fread(buf, 1, i, fp) < 0) {
perror("fread");
return 0;
return EXIT_FAILURE;
}
buf[i] = 0;
@@ -17,5 +18,5 @@ int main(void) {
fclose(fp);
return 0;
return EXIT_SUCCESS;
}
+2 -1
View File
@@ -1,9 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
freopen("stdio/stdio.in", "r", stdin);
char in[6];
fgets(in, 6, stdin);
printf("%s\n", in); // should print Hello
return 0;
return EXIT_SUCCESS;
}
+2 -1
View File
@@ -1,10 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *f = fopen("stdio/stdio.in", "r");
if (fseek(f, 14, SEEK_CUR) < 0) {
puts("fseek error");
return 1;
return EXIT_FAILURE;
}
char buffer[256];
printf("%s", fgets(buffer, 256, f));
+4 -4
View File
@@ -7,18 +7,18 @@ int main(void) {
const char ptr[] = "Hello World!";
if (fwrite(ptr, 0, 17, f)) {
return -1;
return EXIT_FAILURE;
}
if (fwrite(ptr, 7, 0, f)) {
return -1;
return EXIT_FAILURE;
}
if (fwrite(ptr, 0, 0, f)) {
return -1;
return EXIT_FAILURE;
}
fwrite(ptr, sizeof(ptr), 1, f);
fclose(f);
return 0;
return EXIT_SUCCESS;
}
+3 -2
View File
@@ -1,12 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
ungetc('h', stdin);
char c;
if ((c = getchar()) == 'h') {
printf("Worked!\n");
return 0;
return EXIT_SUCCESS;
}
printf("failed :( %c\n", c);
return 0;
return EXIT_FAILURE;
}
+4 -3
View File
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE* f = fopen("stdio/stdio.in", "r");
@@ -10,17 +11,17 @@ int main(void) {
if (!ftrylockfile(f)) {
puts("Mutex unlocked but it shouldn't be");
return -1;
return EXIT_FAILURE;
}
funlockfile(f);
if (ftrylockfile(f)) {
puts("Mutex locked but it shouldn't be");
return -1;
return EXIT_FAILURE;
}
if (!ftrylockfile(f)) {
puts("Mutex unlocked but it shouldn't be");
return -1;
return EXIT_FAILURE;
}
funlockfile(f);
}
+4 -3
View File
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *fp;
@@ -9,7 +10,7 @@ int main(void) {
fp = popen("ls -1 example_dir", "r");
if (fp == NULL) {
perror("popen");
return -1;
return EXIT_FAILURE;
}
while (fgets(path, 256, fp) != NULL) {
@@ -20,10 +21,10 @@ int main(void) {
status = pclose(fp);
if (status == -1) {
perror("pclose");
return -1;
return EXIT_FAILURE;
} else {
printf("status %x\n", status);
}
return 0;
return EXIT_SUCCESS;
}
+2 -1
View File
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int sofar = 0;
@@ -48,5 +49,5 @@ int main(void) {
printf("%G\n", 0.0001);
printf("%G\n", 0.00001);
printf("%E\n", 0.00001);
return 0;
return EXIT_SUCCESS;
}
+3 -2
View File
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -20,8 +21,8 @@ int main(void) {
close(fd);
remove(newpath);
if (strcmp(str, buf) == 0) {
return 0;
return EXIT_SUCCESS;
} else {
return -1;
return EXIT_FAILURE;
}
}
+1 -1
View File
@@ -10,5 +10,5 @@ int main(void) {
char *in = malloc(30);
printf("%s\n", fgets(in, 30, f));
printf("Hello\n");
return 0;
return EXIT_SUCCESS;
}
+3 -2
View File
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
@@ -11,7 +12,7 @@ int main(void) {
);
if (ret != 68) {
printf("Failed! Return value was %d\n", ret);
return -1;
return EXIT_FAILURE;
}
memset(buffer, 0, sizeof(buffer));
@@ -24,7 +25,7 @@ int main(void) {
);
if (ret != 86) {
printf("Failed! Return value was %d\n", ret);
return -1;
return EXIT_FAILURE;
}
puts(buffer);