Skip to content

Commit 8f1959e

Browse files
authored
Merge pull request managarm#1803 from zinnia-os/zinnia-xfce
options/{ansi,posix}: Assortment of fixes for XFCE
2 parents 211321c + be3f8b7 commit 8f1959e

8 files changed

Lines changed: 81 additions & 4 deletions

File tree

options/ansi/generic/file-io.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ int abstract_file::seek(off_t offset, int whence) {
327327
// TODO: If the seek is "small", we can just modify our internal offset.
328328
purge();
329329

330+
// A successful seek clears the end-of-file indicator.
331+
__status_bits &= ~__MLIBC_EOF_BIT;
332+
330333
return 0;
331334
}
332335

options/ansi/generic/stdio.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,27 +1209,33 @@ int do_scanf(H &handler, const Char *fmt, __builtin_va_list args) {
12091209
unsigned long long res = 0;
12101210
char c = handler.look_ahead();
12111211
int digit_count = 0;
1212+
int consumed = 0;
12121213
EOF_CHECK(c == '\0');
12131214

12141215
if(c == '-') {
12151216
handler.consume();
1217+
consumed++;
12161218
is_negative = true;
1217-
} else if(c == '+')
1219+
} else if(c == '+') {
12181220
handler.consume();
1221+
consumed++;
1222+
}
12191223

12201224
c = handler.look_ahead();
1221-
if (c == '0') {
1225+
if (c == '0' && (!width || consumed < width)) {
12221226
handler.consume();
1227+
consumed++;
12231228
c = handler.look_ahead();
1224-
if (tolower(c) == 'x') {
1229+
if (tolower(c) == 'x' && (!width || consumed < width)) {
12251230
handler.consume();
1231+
consumed++;
12261232
c = handler.look_ahead();
12271233
} else {
12281234
digit_count++;
12291235
}
12301236
}
12311237

1232-
while (true) {
1238+
while (!width || consumed < width) {
12331239
if (c >= '0' && c <= '9') {
12341240
handler.consume();
12351241
res = res * 16 + (c - '0');
@@ -1243,6 +1249,7 @@ int do_scanf(H &handler, const Char *fmt, __builtin_va_list args) {
12431249
break;
12441250
}
12451251
digit_count++;
1252+
consumed++;
12461253
c = handler.look_ahead();
12471254
}
12481255
NOMATCH_CHECK(digit_count == 0);

options/posix/include/dirent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct posix_dent {
4646

4747
#if defined(_DEFAULT_SOURCE)
4848
#define IFTODT(mode) (((mode) & 0170000) >> 12)
49+
#define DTTOIF(dirtype) ((dirtype) << 12)
4950
#endif
5051

5152
struct __mlibc_dir_struct {

options/posix/include/sys/param.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
#ifndef _SYS_PARAM_H
33
#define _SYS_PARAM_H
44

5+
#include <abi-bits/dev_t.h>
56
#include <endian.h>
67
#include <limits.h>
78

89
#define NBBY CHAR_BIT
910
#define NGROUPS NGROUPS_MAX
1011

12+
#ifndef NODEV
13+
#define NODEV ((dev_t)(-1))
14+
#endif
15+
1116
/* Report the same value as Linux here. */
1217
#define MAXNAMLEN 255
1318
#define MAXPATHLEN 4096

scripts/rust-libc-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ ignored_macros:
212212
- "CPU_ZERO"
213213
- "CPU_ZERO_S"
214214
- "DOUBLEBITS"
215+
- "DTTOIF"
215216
- "FE_ALL_EXCEPT"
216217
- "FE_DFL_ENV"
217218
- "FLOATBITS"

tests/ansi/fseek-eof.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
#if defined(USE_HOST_LIBC)
6+
#define TEST_FILE "fseek-eof-host-libc.tmp"
7+
#elif defined(USE_CROSS_LIBC)
8+
#define TEST_FILE "fseek-eof-cross-libc.tmp"
9+
#else
10+
#define TEST_FILE "fseek-eof.tmp"
11+
#endif
12+
13+
int main() {
14+
char str[] = "mlibc fseek eof test";
15+
size_t str_size = sizeof(str) - 1;
16+
char buffer[64];
17+
18+
FILE *file = fopen(TEST_FILE, "wb");
19+
assert(file);
20+
assert(fwrite(str, 1, str_size, file) == str_size);
21+
fflush(file);
22+
fclose(file);
23+
24+
file = fopen(TEST_FILE, "rb");
25+
assert(file);
26+
27+
assert(fread(buffer, 1, sizeof(buffer), file) == str_size);
28+
assert(feof(file));
29+
30+
assert(fseek(file, 0, SEEK_SET) == 0);
31+
assert(!feof(file));
32+
33+
assert(fread(buffer, 1, 5, file) == 5);
34+
assert(!memcmp(buffer, "mlibc", 5));
35+
assert(!feof(file));
36+
37+
assert(fread(buffer, 1, sizeof(buffer), file) == str_size - 5);
38+
assert(feof(file));
39+
rewind(file);
40+
assert(!feof(file));
41+
42+
fclose(file);
43+
return 0;
44+
}

tests/ansi/sscanf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,23 @@ int main() {
401401
assert(sscanf("00xc0ffee", "%x", &int_value) == 1);
402402
assert(int_value == 0);
403403

404+
assert(sscanf("1234ab", "%2x", &int_value) == 1);
405+
assert(int_value == 0x12);
406+
assert(sscanf("-1234ab", "%3x", &int_value) == 1);
407+
assert(int_value == -0x12);
408+
assert(sscanf("+1234ab", "%3x", &int_value) == 1);
409+
assert(int_value == 0x12);
410+
assert(sscanf("0x1234", "%4x", &int_value) == 1);
411+
assert(int_value == 0x12);
412+
assert(sscanf("0x1234", "%3x", &int_value) == 1);
413+
assert(int_value == 0x1);
414+
assert(sscanf("-0x1234", "%4x", &int_value) == 1);
415+
assert(int_value == -0x1);
416+
404417
#if (!defined(USE_HOST_LIBC) && !defined(USE_CROSS_LIBC)) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 43)
405418
// glibc before 2.42 or 2.43 did not handle prefixes with no following digits correctly
419+
assert(sscanf("0x12", "%2x", &int_value) == 0);
420+
assert(sscanf("-0x1234", "%3x", &int_value) == 0);
406421
assert(sscanf("0xg", "%x%c", &uint_value, char_value) == 0);
407422
#endif
408423

tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ all_test_cases = [
3434
'ansi/fgetpos',
3535
'ansi/fputs',
3636
'ansi/ftell',
37+
'ansi/fseek-eof',
3738
'ansi/tmpfile',
3839
'ansi/mbstowcs',
3940
'ansi/locale',

0 commit comments

Comments
 (0)