fix: align POSIX stdio and argument handling, clarify Intel iwlwifi licensing

This commit is contained in:
2026-08-09 10:42:09 +02:00
parent a06ef0192d
commit 771c3a5a98
15 changed files with 197 additions and 19 deletions
@@ -0,0 +1,39 @@
Copyright (c) 2006-2015, Intel Corporation.
All rights reserved.
Redistribution. Redistribution and use in binary form, without
modification, are permitted provided that the following conditions are
met:
* Redistributions must reproduce the above copyright notice and the
following disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of Intel Corporation nor the names of its suppliers
may be used to endorse or promote products derived from this software
without specific prior written permission.
* No reverse engineering, decompilation, or disassembly of this software
is permitted.
Limited patent license. Intel Corporation grants a world-wide,
royalty-free, non-exclusive license under patents it now or hereafter
owns or controls to make, have made, use, import, offer to sell and
sell ("Utilize") this software, but solely to the extent that any
such patent is necessary to Utilize the software alone, or in
combination with an operating system licensed under an approved Open
Source license as listed by the Open Source Initiative at
http://opensource.org/licenses. The patent license shall not apply to
any other combinations which include this software. No hardware per
se is licensed hereunder.
DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+8
View File
@@ -34,8 +34,11 @@
#define PRIxPTR "lx"
#define PRIXPTR "lX"
#define PRIdMAX "ld"
#define PRIiMAX "li"
#define PRIuMAX "lu"
#define PRIoMAX "lo"
#define PRIxMAX "lx"
#define PRIXMAX "lX"
#define SCNd8 "d"
#define SCNd16 "d"
@@ -56,5 +59,10 @@
#define SCNdPTR "ld"
#define SCNuPTR "lu"
#define SCNxPTR "lx"
#define SCNdMAX "ld"
#define SCNiMAX "li"
#define SCNuMAX "lu"
#define SCNoMAX "lo"
#define SCNxMAX "lx"
#endif /* _LIBC_INTTYPES_H */
+1 -1
View File
@@ -427,7 +427,7 @@ static inline int mtk_getargs(char *buf, unsigned long max_len) {
}
static inline int mtk_getexecpath(char *buf, unsigned long maxLen) {
return (int)mtk_syscall2(MTK_SYS_GETEXECPATH, (long)buf, (long)maxLen);
return (int)_mtk_syscall2(MTK_SYS_GETEXECPATH, (long)buf, (long)maxLen);
}
static inline int mtk_chdir(const char *path) {
+2 -2
View File
@@ -39,8 +39,8 @@ double atof(const char *s);
int abs(int j);
long labs(long j);
void exit(int status);
void abort(void);
void exit(int status) __attribute__((noreturn));
void abort(void) __attribute__((noreturn));
int atexit(void (*func)(void));
char *getenv(const char *name);
+26 -6
View File
@@ -91,6 +91,14 @@ void _start(void) {
argbuf[len] = '\0';
/* Split on spaces, honouring '...' and "..." so an argument can
contain them: `git commit -m "two words"` has to reach main()
as two arguments, not three. The quotes are removed, and the
token is rewritten in place -- the unquoted form is never
longer than the quoted one, so it always fits. Quotes are the
only metacharacter: there is no escaping and no substitution,
which is deliberate. The kernel hands over one flat string
(SYS_GETARGS) and this is a tokenizer, not a shell. */
char* p = argbuf;
while (*p != '\0' && argc < 255) {
while (*p == ' ') {
@@ -101,15 +109,27 @@ void _start(void) {
break;
}
argv[argc++] = p;
char* out = p;
argv[argc++] = out;
while (*p != '\0' && *p != ' ') {
char quote = 0;
while (*p != '\0' && (quote != 0 || *p != ' ')) {
if (quote == 0 && (*p == '"' || *p == '\'')) {
quote = *p++;
} else if (quote != 0 && *p == quote) {
quote = 0;
p++;
} else {
*out++ = *p++;
}
}
/* Step over the separator before terminating: the write
below lands on the byte p is about to leave behind. */
if (*p != '\0') {
p++;
}
if (*p != '\0') {
*p++ = '\0';
}
*out = '\0';
}
}
Binary file not shown.
+35
View File
@@ -2081,8 +2081,35 @@ int open(const char *path, int flags, ...) {
return h;
}
/*
* The standard descriptors are the terminal, NOT file handles.
*
* 0/1/2 are not handles the kernel ever issued -- SYS_OPEN allocates from its
* own space and would have to return 0 for these to line up, which it does
* not. Passing them to SYS_READ/SYS_FWRITE addresses whatever handle happens
* to hold that number, or fails: before this, every write(2, ...) was
* silently discarded, so a POSIX program that reports errors with write()
* rather than fprintf() printed nothing at all. stdio already routes std
* streams to SYS_PUTCHAR (see fwrite/fprintf); these do the same, so the two
* paths agree.
*/
int read(int fd, void *buf, size_t count) {
if (buf == NULL) return -1;
if (fd == STDIN_FILENO) {
/* Line-oriented, like the terminal itself: return as soon as a
line is complete rather than blocking for the full count. */
char *dst = (char *)buf;
size_t i = 0;
while (i < count) {
int c = fgetc(stdin);
if (c == EOF) break;
dst[i++] = (char)c;
if (c == '\n') break;
}
return (int)i;
}
unsigned long pos = (fd >= 0 && fd < _FD_POS_MAX) ? _fd_pos[fd] : 0;
int ret = (int)_zos_syscall4(SYS_READ, (long)fd, (long)buf, (long)pos, (long)count);
if (ret > 0 && fd >= 0 && fd < _FD_POS_MAX)
@@ -2092,6 +2119,14 @@ int read(int fd, void *buf, size_t count) {
int write(int fd, const void *buf, size_t count) {
if (buf == NULL) return -1;
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
const char *src = (const char *)buf;
for (size_t i = 0; i < count; i++)
_zos_syscall1(SYS_PUTCHAR, (long)(unsigned char)src[i]);
return (int)count;
}
unsigned long pos = (fd >= 0 && fd < _FD_POS_MAX) ? _fd_pos[fd] : 0;
int ret = (int)_zos_syscall4(SYS_FWRITE, (long)fd, (long)buf, (long)pos, (long)count);
if (ret > 0 && fd >= 0 && fd < _FD_POS_MAX)
Binary file not shown.