0.3.0: converge relibc to upstream 0.6.0 + Red Bear patches
This commit is contained in:
+67
-2
@@ -1,4 +1,4 @@
|
||||
#include <malloc.h>
|
||||
#include <malloc.h> /* for pvalloc() */
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -89,7 +89,7 @@ int main(void) {
|
||||
size_t nonpow2_mul_voidptr_size = 3*sizeof(void *);
|
||||
size_t pow2_mul_voidptr_size = 4*sizeof(void *);
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
errno = 0;
|
||||
char * ptr_zerosize_malloc = (char *)malloc(zero_size);
|
||||
@@ -165,7 +165,26 @@ int main(void) {
|
||||
printf("realloc (SIZE_MAX): ");
|
||||
test_cannot_alloc(ptr_realloc_maxsize, realloc_maxsize_errno);
|
||||
free(ptr_realloc_maxsize);
|
||||
|
||||
errno = 0;
|
||||
char * ptr_reallocarray_maxsize = (char *)malloc(sample_alloc_size);
|
||||
ptr_reallocarray_maxsize = (char *)reallocarray(ptr_reallocarray_maxsize, 2, sample_alloc_size);
|
||||
int reallocarray_errno = errno;
|
||||
printf("reallocarray: ");
|
||||
test_non_null(ptr_reallocarray_maxsize, reallocarray_errno);
|
||||
for(i = 0; i < sample_realloc_size; i++) {
|
||||
ptr_realloc[i] = (char)i;
|
||||
}
|
||||
errno = 0;
|
||||
ptr_reallocarray_maxsize = (char *)reallocarray(ptr_reallocarray_maxsize, 2, max_size);
|
||||
reallocarray_errno = errno;
|
||||
printf("reallocarray (SIZE_MAX): ");
|
||||
test_cannot_alloc(ptr_reallocarray_maxsize, reallocarray_errno);
|
||||
free(ptr_reallocarray_maxsize);
|
||||
|
||||
// Warning for deprecated functions is expected so silence -Werror
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
errno = 0;
|
||||
char * ptr_memalign_size0 = (char *)memalign(aligned_alloc_alignment, zero_size);
|
||||
int memalign_size0_errno = errno;
|
||||
@@ -203,6 +222,8 @@ int main(void) {
|
||||
printf("memalign (alignment 3): ");
|
||||
test_invalid_aligned(ptr_memalign_align3, memalign_align3_errno);
|
||||
free(ptr_memalign_align3);
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
errno = 0;
|
||||
char * ptr_aligned_alloc_goodsize = (char *)aligned_alloc(aligned_alloc_alignment, aligned_alloc_goodsize);
|
||||
@@ -218,6 +239,10 @@ int main(void) {
|
||||
test_invalid_aligned(ptr_aligned_alloc_badsize, aligned_alloc_badsize_errno);
|
||||
free(ptr_aligned_alloc_badsize);
|
||||
|
||||
// Warning for deprecated functions is expected so silence -Werror
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
errno = 0;
|
||||
char * ptr_valloc_size0 = (char *)valloc(zero_size);
|
||||
int valloc_size0_errno = errno;
|
||||
@@ -273,4 +298,44 @@ int main(void) {
|
||||
printf("posix_memalign (SIZE_MAX): ");
|
||||
test_cannot_alloc(ptr_posix_memalign_maxsize, posix_memalign_maxsize_return);
|
||||
free(ptr_posix_memalign_maxsize);
|
||||
|
||||
errno = 0;
|
||||
char * ptr_pvalloc_size0 = (char *)pvalloc(zero_size);
|
||||
int pvalloc_size0_errno = errno;
|
||||
printf("pvalloc (size 0): ");
|
||||
test_size_zero(ptr_pvalloc_size0, page_size, pvalloc_size0_errno);
|
||||
free(ptr_pvalloc_size0);
|
||||
|
||||
errno = 0;
|
||||
char * ptr_pvalloc = (char *)pvalloc(sample_alloc_size);
|
||||
int pvalloc_errno = errno;
|
||||
printf("pvalloc: ");
|
||||
test_valid_aligned(ptr_pvalloc, page_size, pvalloc_errno);
|
||||
/* Check that the alloc size is rounded up to nearest page-size
|
||||
* multiple */
|
||||
for(i = 0; i < page_size; i++) {
|
||||
ptr_pvalloc[i] = (char)i;
|
||||
}
|
||||
free(ptr_pvalloc);
|
||||
|
||||
errno = 0;
|
||||
char * ptr_pvalloc_multipage = (char *)pvalloc(page_size + 1);
|
||||
int pvalloc_multipage_errno = errno;
|
||||
printf("pvalloc (2 pages): ");
|
||||
test_valid_aligned(ptr_pvalloc_multipage, page_size, pvalloc_multipage_errno);
|
||||
/* Check that the alloc size is rounded up to nearest page-size
|
||||
* multiple */
|
||||
for(i = 0; i < 2*page_size; i++) {
|
||||
ptr_pvalloc_multipage[i] = (char)i;
|
||||
}
|
||||
free(ptr_pvalloc_multipage);
|
||||
|
||||
errno = 0;
|
||||
char * ptr_pvalloc_maxsize = (char *)pvalloc(max_size);
|
||||
int pvalloc_maxsize_errno = errno;
|
||||
printf("pvalloc (SIZE_MAX): ");
|
||||
test_cannot_alloc(ptr_pvalloc_maxsize, pvalloc_maxsize_errno);
|
||||
free(ptr_pvalloc_maxsize);
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
@@ -6,4 +6,7 @@
|
||||
int main(void) {
|
||||
double d = atof("-3.14");
|
||||
printf("%f\n", d);
|
||||
|
||||
d = atof("INF");
|
||||
printf("%f\n", d);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void) {
|
||||
char *const tokens[] = {
|
||||
"ro",
|
||||
"rw",
|
||||
"foo",
|
||||
"baz",
|
||||
NULL
|
||||
};
|
||||
|
||||
// getsubopt modifies the string in-place
|
||||
char opt_str[] = "ro,foo=bar,bool,baz=,rw";
|
||||
char *options = opt_str;
|
||||
char *value = NULL;
|
||||
int idx;
|
||||
|
||||
idx = getsubopt(&options, tokens, &value);
|
||||
UNEXP_IF(getsubopt, idx, != 0);
|
||||
if (value != NULL) {
|
||||
printf("getsubopt failed: expected NULL value for 'ro', got '%s'\n", value);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
idx = getsubopt(&options, tokens, &value);
|
||||
UNEXP_IF(getsubopt, idx, != 2);
|
||||
if (value == NULL || strcmp(value, "bar") != 0) {
|
||||
printf("getsubopt failed: expected 'bar', got '%s'\n", value ? value : "NULL");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
idx = getsubopt(&options, tokens, &value);
|
||||
UNEXP_IF(getsubopt, idx, != -1);
|
||||
if (value == NULL || strcmp(value, "bool") != 0) {
|
||||
printf("getsubopt failed: expected 'bool' in value, got '%s'\n", value ? value : "NULL");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
idx = getsubopt(&options, tokens, &value);
|
||||
UNEXP_IF(getsubopt, idx, != 3);
|
||||
if (value == NULL || strcmp(value, "") != 0) {
|
||||
printf("getsubopt failed: expected empty string value, got '%s'\n", value ? value : "NULL");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
idx = getsubopt(&options, tokens, &value);
|
||||
UNEXP_IF(getsubopt, idx, != 1);
|
||||
if (value != NULL) {
|
||||
printf("getsubopt failed: expected NULL value for 'rw', got '%s'\n", value);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
idx = getsubopt(&options, tokens, &value);
|
||||
UNEXP_IF(getsubopt, idx, != -1);
|
||||
}
|
||||
@@ -7,7 +7,10 @@
|
||||
int main(void) {
|
||||
char* string = (char*) calloc(20, sizeof(char));
|
||||
strcpy(string, "tempXXXXXX");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
mktemp(string);
|
||||
#pragma GCC diagnostic pop
|
||||
printf("%s\n",string);
|
||||
free(string);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/* Test for ptsname/ptsname_r.
|
||||
Copyright (C) 2014-2024 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEV_TTY "/dev/tty"
|
||||
#define PTSNAME_EINVAL "./ptsname-einval"
|
||||
|
||||
int do_single_test(int fd, char * buf, size_t buflen, int expected_err) {
|
||||
|
||||
int ret = ptsname_r(fd, buf, buflen);
|
||||
int err = errno;
|
||||
|
||||
if (expected_err == 0) {
|
||||
if (ret != 0) {
|
||||
printf("ptsname_r: expected: return = 0\n");
|
||||
printf(" got: return = %d, errno = %d (%s)\n",
|
||||
ret, err, strerror(err));
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (ret == 0 || errno != expected_err) {
|
||||
printf("ptsname_r: expected: return = %d, errno = %d (%s)\n",
|
||||
-1, expected_err, strerror(expected_err));
|
||||
printf(" got: return = %d, errno = %d (%s)\n",
|
||||
ret, err, strerror(err));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char buf[512] = {0};
|
||||
int result = 0;
|
||||
errno = 0;
|
||||
/* Tests with a real PTS master. */
|
||||
int fd = posix_openpt(O_RDWR);
|
||||
if (fd != -1) {
|
||||
result |= do_single_test(fd, buf, sizeof(buf), 0);
|
||||
result |= do_single_test(fd, buf, 1, ERANGE);
|
||||
close(fd);
|
||||
} else
|
||||
printf("posix_openpt (O_RDWR) failed\nerrno %d (%s)\n",
|
||||
errno, strerror(errno));
|
||||
|
||||
// TODO: open(DEV_TTY, O_RDONLY) gives error on CI
|
||||
// /* Test with a terminal device which is not a PTS master. */
|
||||
// fd = open(DEV_TTY, O_RDONLY);
|
||||
// if (fd != -1) {
|
||||
// result |= do_single_test(fd, buf, sizeof(buf), ENOTTY);
|
||||
// close(fd);
|
||||
// } else
|
||||
// printf("open (\"%s\", O_RDWR) failed\nerrno %d (%s)\n",
|
||||
// DEV_TTY, errno, strerror(errno));
|
||||
|
||||
/* Test with a file. */
|
||||
fd = open(PTSNAME_EINVAL, O_RDWR | O_CREAT, 0600);
|
||||
if (fd != -1) {
|
||||
result |= do_single_test(fd, buf, sizeof(buf), ENOTTY);
|
||||
close(fd);
|
||||
unlink(PTSNAME_EINVAL);
|
||||
} else
|
||||
printf("open (\"%s\", O_RDWR | OCREAT) failed\nerrno %d (%s)\n",
|
||||
PTSNAME_EINVAL, errno, strerror(errno));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
int values[] = { 23, 16, 8, 4, 42, 15 };
|
||||
|
||||
int cmpfunc (const void * a_ptr, const void * b_ptr) {
|
||||
int a = *(const int *)a_ptr;
|
||||
int b = *(const int *)b_ptr;
|
||||
return a - b;
|
||||
}
|
||||
|
||||
int main () {
|
||||
size_t i;
|
||||
|
||||
printf("Before: ");
|
||||
for(i = 0; i < ARRAY_SIZE(values); i++) {
|
||||
printf("%d ", values[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
qsort(values, ARRAY_SIZE(values), sizeof(int), cmpfunc);
|
||||
|
||||
printf("After: ");
|
||||
for(i = 0; i < ARRAY_SIZE(values); i++) {
|
||||
printf("%d ", values[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+64
-2
@@ -1,3 +1,4 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -10,9 +11,70 @@ int main(void) {
|
||||
char* inputs[] = {
|
||||
"a 1 hello", " 1 hello", "1 hello 2",
|
||||
"10.123", "010.123", "-5.3",
|
||||
"0x10.123", "0x1.23", "0x3.21"
|
||||
"0x10.123", "0x1.23", "0x3.21",
|
||||
|
||||
"1e5", "1e+5", "1e-5",
|
||||
"1e5 ", "1e+5 ", "1e-5 ",
|
||||
|
||||
"1e10", "1eXXXX", "1e", "1e ",
|
||||
"1e+10", "1e+XXXX", "1e+", "1e+ ",
|
||||
"1e-10", "1e-XXXX", "1e-", "1e- ",
|
||||
|
||||
"-1e5", "-1e+5", "-1e-5",
|
||||
"-1e5 ", "-1e+5 ", "-1e-5 ",
|
||||
|
||||
"-1e10", "-1eXXXX", "-1e", "-1e ",
|
||||
"-1e+10", "-1e+XXXX", "-1e+", "-1e+ ",
|
||||
"-1e-10", "-1e-XXXX", "-1e-", "-1e- ",
|
||||
|
||||
"12.34e5", "12.34e+5", "12.34e-5",
|
||||
"12.34e5 ", "12.34e+5 ", "12.34e-5 ",
|
||||
|
||||
"12.34e10", "12.34eXXXX", "12.34e", "12.34e ",
|
||||
"12.34e+10", "12.34e+XXXX", "12.34e+", "12.34e+ ",
|
||||
"12.34e-10", "12.34e-XXXX", "12.34e-", "12.34e- ",
|
||||
|
||||
"-12.34e5", "-12.34e+5", "-12.34e-5",
|
||||
"-12.34e5 ", "-12.34e+5 ", "-12.34e-5 ",
|
||||
|
||||
"-12.34e10", "-12.34eXXXX", "-12.34e", "-12.34e ",
|
||||
"-12.34e+10", "-12.34e+XXXX", "-12.34e+", "-12.34e+ ",
|
||||
"-12.34e-10", "-12.34e-XXXX", "-12.34e-", "-12.34e- ",
|
||||
|
||||
"0x0.3p10", "-0x0.3p10", "0x0.3p-5", "-0x0.3p-5",
|
||||
"0x1.4p3", "0x1.4p-3", "-0x1.4p3", "-0x1.4p-3",
|
||||
"0x10.1p0", "0x10.1p-0", "-0x10.1p0", "-0x10.1p-0",
|
||||
|
||||
"0.5e0", "0.5e1", "0.5e2", "0.5e3", "0.5e4",
|
||||
"0.5e5", "0.5e6", "0.5e7", "0.5e8", "0.5e9",
|
||||
"0.5e10", "0.5e11", "0.5e12", "0.5e13", "0.5e14",
|
||||
"0.5e15", "0.5e16", "0.5e17", "0.5e18", "0.5e19",
|
||||
"0.5e20", "0.5e21", "0.5e22", "0.5e23", "0.5e24",
|
||||
"0.5e25", "0.5e26", "0.5e27", "0.5e28", "0.5e29",
|
||||
"0.5e30", "0.5e31", "0.5e32", "0.5e33", "0.5e34",
|
||||
"0.5e35", "0.5e36", "0.5e37", "0.5e38",
|
||||
|
||||
"-0.5e0", "-0.5e1", "-0.5e2", "-0.5e3", "-0.5e4",
|
||||
"-0.5e5", "-0.5e6", "-0.5e7", "-0.5e8", "-0.5e9",
|
||||
"-0.5e10", "-0.5e11", "-0.5e12", "-0.5e13", "-0.5e14",
|
||||
"-0.5e15", "-0.5e16", "-0.5e17", "-0.5e18", "-0.5e19",
|
||||
"-0.5e20", "-0.5e21", "-0.5e22", "-0.5e23", "-0.5e24",
|
||||
"-0.5e25", "-0.5e26", "-0.5e27", "-0.5e28", "-0.5e29",
|
||||
"-0.5e30", "-0.5e31", "-0.5e32", "-0.5e33", "-0.5e34",
|
||||
"-0.5e35", "-0.5e36", "-0.5e37", "-0.5e38",
|
||||
|
||||
"-0",
|
||||
|
||||
"INF", "inf", "iNf", "Inf foobarbaz",
|
||||
"+INF", "+inf", "+iNf", "+Inf foobarbaz",
|
||||
"-INF", "-inf", "-iNf", "-Inf foobarbaz",
|
||||
|
||||
"NaN0.1e5", "nan-37", "nAn1.05", "Nan foo bar baz",
|
||||
"+NaN0.1e5", "+nan-37", "+nAn1.05", "+Nan foo bar baz",
|
||||
"-NaN0.1e5", "-nan-37", "-nAn1.05", "-Nan foo bar baz",
|
||||
|
||||
};
|
||||
for (int i = 0; i < sizeof(inputs) / sizeof(char*); i += 1) {
|
||||
for (size_t i = 0; i < sizeof(inputs) / sizeof(char*); i += 1) {
|
||||
d = strtod(inputs[i], &endptr);
|
||||
printf("d: %f Endptr: \"%s\"\n", d, endptr);
|
||||
}
|
||||
|
||||
+28
-13
@@ -5,27 +5,42 @@
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void) {
|
||||
printf("%ld\n", strtol(" -42", NULL, 0));
|
||||
printf("%ld\n", strtol(" +555", NULL, 0));
|
||||
printf("%ld\n", strtol(" 1234567890 ", NULL, 0));
|
||||
char *endptr;
|
||||
|
||||
printf("%ld\n", strtol(" -42", NULL, 10));
|
||||
printf("%ld\n", strtol(" +555", NULL, 10));
|
||||
printf("%ld\n", strtol(" 1234567890 ", NULL, 10));
|
||||
printf("%ld\n", strtol(" -42", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtol(" +555", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtol(" 1234567890 ", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lx\n", strtol(" 0x38Acfg", NULL, 0));
|
||||
printf("%lx\n", strtol("0Xabcdef12", NULL, 16));
|
||||
printf("%lx\n", strtol("cafebeef", NULL, 16));
|
||||
printf("%ld\n", strtol(" -42", &endptr, 10));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtol(" +555", &endptr, 10));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtol(" 1234567890 ", &endptr, 10));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lo\n", strtol(" 073189", NULL, 0));
|
||||
printf("%lo\n", strtol(" 073189", NULL, 8));
|
||||
printf("%lx\n", strtol(" 0x38Acfg", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lx\n", strtol("0Xabcdef12", &endptr, 16));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lx\n", strtol("cafebeef", &endptr, 16));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lo\n", strtol(" 0b", NULL, 8));
|
||||
printf("%lo\n", strtol(" 073189", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lo\n", strtol(" 073189", &endptr, 8));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lo\n", strtol(" 0b", &endptr, 8));
|
||||
if(errno != 0) {
|
||||
printf("errno is not 0 (%d), something went wrong\n", errno);
|
||||
}
|
||||
printf("%lo\n", strtol(" 0b", NULL, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lo\n", strtol(" 0b", &endptr, 0));
|
||||
if(errno != 0) {
|
||||
printf("errno is not 0 (%d), something went wrong\n", errno);
|
||||
}
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
}
|
||||
|
||||
+27
-11
@@ -5,26 +5,42 @@
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void) {
|
||||
printf("%ld\n", strtoul(" -42", NULL, 0));
|
||||
printf("%ld\n", strtoul(" +555", NULL, 0));
|
||||
printf("%ld\n", strtoul(" 1234567890 ", NULL, 0));
|
||||
char *endptr;
|
||||
|
||||
printf("%ld\n", strtoul(" -42", NULL, 10));
|
||||
printf("%ld\n", strtoul(" +555", NULL, 10));
|
||||
printf("%ld\n", strtoul(" 1234567890 ", NULL, 10));
|
||||
printf("%ld\n", strtoul(" -42", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtoul(" +555", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtoul(" 1234567890 ", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lx\n", strtoul(" 0x38Acfg", NULL, 0));
|
||||
printf("%lx\n", strtoul("0Xabcdef12", NULL, 16));
|
||||
printf("%ld\n", strtoul(" -42", &endptr, 10));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtoul(" +555", &endptr, 10));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%ld\n", strtoul(" 1234567890 ", &endptr, 10));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lo\n", strtoul(" 073189", NULL, 0));
|
||||
printf("%lo\n", strtoul(" 073189", NULL, 8));
|
||||
printf("%lx\n", strtoul(" 0x38Acfg", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lx\n", strtoul("0Xabcdef12", &endptr, 16));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lx\n", strtoul("0x21000004", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lo\n", strtoul(" 0b", NULL, 8));
|
||||
printf("%lo\n", strtoul(" 073189", &endptr, 0));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lo\n", strtoul(" 073189", &endptr, 8));
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
|
||||
printf("%lo\n", strtoul(" 0b", &endptr, 8));
|
||||
if(errno != 0) {
|
||||
printf("errno is not 0 (%d), something went wrong\n", errno);
|
||||
}
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
printf("%lo\n", strtoul(" 0b", NULL, 0));
|
||||
if(errno != 0) {
|
||||
printf("errno is not 0 (%d), something went wrong\n", errno);
|
||||
}
|
||||
printf("endptr \"%s\"\n", endptr);
|
||||
}
|
||||
|
||||
+11
-1
@@ -3,6 +3,16 @@
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void) {
|
||||
int status = system("echo test of system");
|
||||
// testing shell detection
|
||||
// this means, because we don't detect if a shell actually exists but just assume it does, this test case breaks in
|
||||
// environments without `sh`. I think that is a reasonable tradeoff.
|
||||
// (And if there isn't a shell, system() won't work anyways)
|
||||
int status = system(NULL);
|
||||
printf("shell found: %i\n", status);
|
||||
fflush(stdout);
|
||||
ERROR_IF(system, status, == 0);
|
||||
|
||||
// base case
|
||||
status = system("echo test of system");
|
||||
ERROR_IF(system, status, == -1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user