Wrap single line statements inside braces.
This commit is contained in:
+1
-2
@@ -4,9 +4,9 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "string.h"
|
||||
#include "signal.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
/// @brief Since there could be signal handlers listening for the abort, we need
|
||||
/// to keep track at which stage of the abort we are.
|
||||
@@ -28,7 +28,6 @@ void abort(void)
|
||||
|
||||
/* Send signal which possibly calls a user handler. */
|
||||
if (stage == 1) {
|
||||
|
||||
// We must allow recursive calls of abort
|
||||
int save_stage = stage;
|
||||
|
||||
|
||||
+1
-1
@@ -4,8 +4,8 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
void __assert_fail(const char *assertion, const char *file, const char *function, unsigned int line)
|
||||
{
|
||||
|
||||
+2
-1
@@ -83,8 +83,9 @@ static void cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, unsig
|
||||
*p1 = '1';
|
||||
(*decpt)++;
|
||||
if (eflag == 0) {
|
||||
if (p > buf)
|
||||
if (p > buf) {
|
||||
*p = '0';
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
+29
-17
@@ -4,13 +4,13 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "grp.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "sys/errno.h"
|
||||
#include "io/debug.h"
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "fcntl.h"
|
||||
#include "io/debug.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/unistd.h"
|
||||
|
||||
/// Holds the file descriptor while we are working with `/etc/group`.
|
||||
static int __fd = -1;
|
||||
@@ -24,14 +24,17 @@ static inline void __parse_line(group_t *grp, char *buf)
|
||||
assert(grp && "Received null grp!");
|
||||
char *token;
|
||||
// Parse the group name.
|
||||
if ((token = strtok(buf, ":")) != NULL)
|
||||
if ((token = strtok(buf, ":")) != NULL) {
|
||||
grp->gr_name = token;
|
||||
}
|
||||
// Parse the group passwd.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
grp->gr_passwd = token;
|
||||
}
|
||||
// Parse the group id.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
grp->gr_gid = atoi(token);
|
||||
}
|
||||
|
||||
size_t found_users = 0;
|
||||
while ((token = strtok(NULL, ",\n\0")) != NULL && found_users < MAX_MEMBERS_PER_GROUP) {
|
||||
@@ -57,8 +60,9 @@ static inline char *__search_entry(int fd, char *buf, int buflen, const char *na
|
||||
int pos = 0;
|
||||
while ((ret = read(fd, &c, 1U))) {
|
||||
// Skip carriage return.
|
||||
if (c == '\r')
|
||||
if (c == '\r') {
|
||||
continue;
|
||||
}
|
||||
if (pos >= buflen) {
|
||||
errno = ERANGE;
|
||||
return NULL;
|
||||
@@ -69,8 +73,9 @@ static inline char *__search_entry(int fd, char *buf, int buflen, const char *na
|
||||
buf[pos] = 0;
|
||||
// Check the entry.
|
||||
if (name) {
|
||||
if (strncmp(buf, name, strlen(name)) == 0)
|
||||
if (strncmp(buf, name, strlen(name)) == 0) {
|
||||
return buf;
|
||||
}
|
||||
} else {
|
||||
int gid_start = -1, col_count = 0;
|
||||
for (int i = 0; i < pos; ++i) {
|
||||
@@ -85,15 +90,17 @@ static inline char *__search_entry(int fd, char *buf, int buflen, const char *na
|
||||
// Parse the gid.
|
||||
int found_gid = atoi(&buf[gid_start]);
|
||||
// Check the gid.
|
||||
if (found_gid == gid)
|
||||
if (found_gid == gid) {
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reset the index.
|
||||
pos = 0;
|
||||
// If we have reached the EOF stop.
|
||||
if (ret == EOF)
|
||||
if (ret == EOF) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
buf[pos++] = c;
|
||||
}
|
||||
@@ -108,23 +115,26 @@ group_t *getgrgid(gid_t gid)
|
||||
static char buffer[BUFSIZ];
|
||||
|
||||
group_t *result;
|
||||
if (!getgrgid_r(gid, &grp, buffer, BUFSIZ, &result))
|
||||
if (!getgrgid_r(gid, &grp, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &grp;
|
||||
}
|
||||
|
||||
group_t *getgrnam(const char *name)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static group_t grp;
|
||||
static char buffer[BUFSIZ];
|
||||
|
||||
group_t *result;
|
||||
if (!getgrnam_r(name, &grp, buffer, BUFSIZ, &result))
|
||||
if (!getgrnam_r(name, &grp, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &grp;
|
||||
}
|
||||
@@ -199,8 +209,9 @@ group_t *getgrent(void)
|
||||
static char buffer[BUFSIZ];
|
||||
while ((ret = read(__fd, &c, 1U))) {
|
||||
// Skip carriage return.
|
||||
if (c == '\r')
|
||||
if (c == '\r') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pos >= BUFSIZ) {
|
||||
errno = ERANGE;
|
||||
@@ -220,8 +231,9 @@ group_t *getgrent(void)
|
||||
}
|
||||
|
||||
// If we have reached the EOF stop.
|
||||
if (ret == EOF)
|
||||
if (ret == EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
buffer[pos++] = c;
|
||||
|
||||
+12
-8
@@ -4,12 +4,12 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "io/debug.h"
|
||||
#include "io/port_io.h"
|
||||
#include "io/ansi_colors.h"
|
||||
#include "sys/bitops.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "io/port_io.h"
|
||||
#include "math.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/bitops.h"
|
||||
|
||||
/// Serial port for QEMU.
|
||||
#define SERIAL_COM1 (0x03F8)
|
||||
@@ -23,8 +23,9 @@ void dbg_putchar(char c)
|
||||
|
||||
void dbg_puts(const char *s)
|
||||
{
|
||||
while ((*s) != 0)
|
||||
while ((*s) != 0) {
|
||||
dbg_putchar(*s++);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void __debug_print_header(const char *file, const char *fun, int line, short log_level, char *header)
|
||||
@@ -76,8 +77,9 @@ static inline void __debug_print_header(const char *file, const char *fun, int l
|
||||
|
||||
void set_log_level(int level)
|
||||
{
|
||||
if ((level >= LOGLEVEL_EMERG) && (level <= LOGLEVEL_DEBUG))
|
||||
if ((level >= LOGLEVEL_EMERG) && (level <= LOGLEVEL_DEBUG)) {
|
||||
max_log_level = level;
|
||||
}
|
||||
}
|
||||
|
||||
int get_log_level()
|
||||
@@ -92,8 +94,9 @@ void dbg_printf(const char *file, const char *fun, int line, char *header, short
|
||||
static short new_line = 1;
|
||||
|
||||
// Stage 1: FORMAT
|
||||
if (strlen(format) >= BUFSIZ)
|
||||
if (strlen(format) >= BUFSIZ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start variabile argument's list.
|
||||
va_list ap;
|
||||
@@ -132,8 +135,9 @@ const char *to_human_size(unsigned long bytes)
|
||||
int i = 0;
|
||||
double dblBytes = bytes;
|
||||
if (bytes > 1024) {
|
||||
for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024)
|
||||
for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024) {
|
||||
dblBytes = bytes / 1024.0;
|
||||
}
|
||||
}
|
||||
sprintf(output, "%.02lf %2s", dblBytes, suffix[i]);
|
||||
return output;
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "assert.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
/// @brief Reference to the `environ` variable in `setenv.c`.
|
||||
extern char **environ;
|
||||
|
||||
+4
-4
@@ -3,13 +3,13 @@
|
||||
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "libgen.h"
|
||||
#include "io/debug.h"
|
||||
#include "limits.h"
|
||||
#include "string.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/unistd.h>
|
||||
#include "libgen.h"
|
||||
#include "string.h"
|
||||
#include "limits.h"
|
||||
#include "io/debug.h"
|
||||
|
||||
int dirname(const char *path, char *buffer, size_t buflen)
|
||||
{
|
||||
|
||||
+10
-5
@@ -18,26 +18,30 @@ double round(double x)
|
||||
double floor(double x)
|
||||
{
|
||||
if (x > -1.0 && x < 1.0) {
|
||||
if (x >= 0)
|
||||
if (x >= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
int i = (int)x;
|
||||
if (x < 0)
|
||||
if (x < 0) {
|
||||
return (double)(i - 1);
|
||||
}
|
||||
return (double)i;
|
||||
}
|
||||
|
||||
double ceil(double x)
|
||||
{
|
||||
if (x > -1.0 && x < 1.0) {
|
||||
if (x <= 0)
|
||||
if (x <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
int i = (int)x;
|
||||
if (x > 0)
|
||||
if (x > 0) {
|
||||
return (double)(i + 1);
|
||||
}
|
||||
return (double)i;
|
||||
}
|
||||
|
||||
@@ -145,8 +149,9 @@ double ln(double x)
|
||||
double logx(double x, double y)
|
||||
{
|
||||
// Base may not equal 1 or be negative.
|
||||
if (y == 1.f || y < 0.f || ln(y) == 0.f)
|
||||
if (y == 1.f || y < 0.f || ln(y) == 0.f) {
|
||||
return 0.f;
|
||||
}
|
||||
return ln(x) / ln(y);
|
||||
}
|
||||
|
||||
|
||||
+36
-21
@@ -4,13 +4,13 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "pwd.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "sys/errno.h"
|
||||
#include "io/debug.h"
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "fcntl.h"
|
||||
#include "io/debug.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/unistd.h"
|
||||
|
||||
/// @brief Parses the input buffer and fills pwd with its details.
|
||||
/// @param pwd the structure we need to fill.
|
||||
@@ -20,32 +20,40 @@ static inline void __parse_line(passwd_t *pwd, char *buf)
|
||||
assert(pwd && "Received null pwd!");
|
||||
char *token, *ch;
|
||||
// Parse the username.
|
||||
if ((token = strtok(buf, ":")) != NULL)
|
||||
if ((token = strtok(buf, ":")) != NULL) {
|
||||
pwd->pw_name = token;
|
||||
}
|
||||
// Parse the password.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_passwd = token;
|
||||
}
|
||||
// Parse the user ID.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_uid = atoi(token);
|
||||
}
|
||||
// Parse the group ID.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_gid = atoi(token);
|
||||
}
|
||||
// Parse the user information.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_gecos = token;
|
||||
}
|
||||
// Parse the dir.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_dir = token;
|
||||
}
|
||||
// Parse the shell.
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_shell = token;
|
||||
// Find carriege return.
|
||||
if ((ch = strchr(pwd->pw_shell, '\r')))
|
||||
if ((ch = strchr(pwd->pw_shell, '\r'))) {
|
||||
*ch = 0;
|
||||
}
|
||||
// Find newline.
|
||||
if ((ch = strchr(pwd->pw_shell, '\n')))
|
||||
if ((ch = strchr(pwd->pw_shell, '\n'))) {
|
||||
*ch = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +79,7 @@ ssize_t __readline(int fd, char *buffer, size_t buflen)
|
||||
}
|
||||
}
|
||||
}
|
||||
long newline_len = (int)(newline - buffer);
|
||||
long newline_len = (newline - buffer);
|
||||
if (newline_len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -106,17 +114,20 @@ static inline char *__search_entry(int fd, char *buffer, int buflen, const char
|
||||
} else {
|
||||
// Name
|
||||
char *ptr = strchr(buffer, ':');
|
||||
if (ptr == NULL)
|
||||
if (ptr == NULL) {
|
||||
continue;
|
||||
}
|
||||
// Password
|
||||
++ptr;
|
||||
char *uid_start = strchr(ptr, ':');
|
||||
if (uid_start == NULL)
|
||||
if (uid_start == NULL) {
|
||||
continue;
|
||||
}
|
||||
++uid_start;
|
||||
ptr = strchr(uid_start, ':');
|
||||
if (ptr == NULL)
|
||||
if (ptr == NULL) {
|
||||
continue;
|
||||
}
|
||||
*ptr = '\0';
|
||||
// Parse the uid.
|
||||
int found_uid = atoi(uid_start);
|
||||
@@ -132,13 +143,15 @@ static inline char *__search_entry(int fd, char *buffer, int buflen, const char
|
||||
|
||||
passwd_t *getpwnam(const char *name)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
static passwd_t pwd;
|
||||
static char buffer[BUFSIZ];
|
||||
passwd_t *result;
|
||||
if (!getpwnam_r(name, &pwd, buffer, BUFSIZ, &result))
|
||||
if (!getpwnam_r(name, &pwd, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
return &pwd;
|
||||
}
|
||||
|
||||
@@ -147,15 +160,17 @@ passwd_t *getpwuid(uid_t uid)
|
||||
static passwd_t pwd;
|
||||
static char buffer[BUFSIZ];
|
||||
passwd_t *result;
|
||||
if (!getpwuid_r(uid, &pwd, buffer, BUFSIZ, &result))
|
||||
if (!getpwuid_r(uid, &pwd, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
return &pwd;
|
||||
}
|
||||
|
||||
int getpwnam_r(const char *name, passwd_t *pwd, char *buf, size_t buflen, passwd_t **result)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NULL) {
|
||||
return 0;
|
||||
}
|
||||
int fd = open("/etc/passwd", O_RDONLY, 0);
|
||||
if (fd == -1) {
|
||||
pr_debug("Cannot open `/etc/passwd`\n");
|
||||
|
||||
+1
-1
@@ -4,8 +4,8 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sched.h"
|
||||
#include "sys/errno.h"
|
||||
|
||||
_syscall2(int, sched_setparam, pid_t, pid, const sched_param_t *, param)
|
||||
|
||||
|
||||
+11
-7
@@ -3,10 +3,10 @@
|
||||
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include <assert.h>
|
||||
#include "sys/errno.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include <assert.h>
|
||||
|
||||
char **environ;
|
||||
|
||||
@@ -23,9 +23,11 @@ static inline int __find_entry(const char *name, const size_t name_len)
|
||||
{
|
||||
if (environ) {
|
||||
int index = 0;
|
||||
for (char **ptr = environ; *ptr; ++ptr, ++index)
|
||||
if (!strncmp((*ptr), name, name_len) && (*ptr)[name_len] == '=')
|
||||
for (char **ptr = environ; *ptr; ++ptr, ++index) {
|
||||
if (!strncmp((*ptr), name, name_len) && (*ptr)[name_len] == '=') {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -98,8 +100,9 @@ int setenv(const char *name, const char *value, int replace)
|
||||
environ = __environ = new_environ;
|
||||
}
|
||||
// Free the previous entry.
|
||||
if (environ[index])
|
||||
if (environ[index]) {
|
||||
free(environ[index]);
|
||||
}
|
||||
// Allocate the new entry.
|
||||
environ[index] = malloc(total_len);
|
||||
// Memcopy because we do not want the null terminating character.
|
||||
@@ -129,8 +132,9 @@ int unsetenv(const char *name)
|
||||
if (!strncmp(*ep, name, len) && (*ep)[len] == '=') {
|
||||
/* Found it. Remove this pointer by moving later ones back. */
|
||||
char **dp = ep;
|
||||
do dp[0] = dp[1];
|
||||
while (*dp++);
|
||||
do {
|
||||
dp[0] = dp[1];
|
||||
} while (*dp++);
|
||||
/* Continue the loop in case NAME appears again. */
|
||||
} else {
|
||||
++ep;
|
||||
|
||||
+4
-3
@@ -4,10 +4,10 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "stddef.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "assert.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
/// @brief Number which identifies a memory area allocated through a call to
|
||||
/// malloc(), calloc() or realloc().
|
||||
@@ -37,8 +37,9 @@ void *malloc(unsigned int size)
|
||||
void *calloc(size_t num, size_t size)
|
||||
{
|
||||
void *ptr = malloc(num * size);
|
||||
if (ptr)
|
||||
if (ptr) {
|
||||
memset(ptr, 0, num * size);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
+20
-13
@@ -5,9 +5,9 @@
|
||||
|
||||
#include "string.h"
|
||||
#include "ctype.h"
|
||||
#include "fcntl.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "fcntl.h"
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include "mem/kheap.h"
|
||||
@@ -25,8 +25,9 @@ char *strncpy(char *destination, const char *source, size_t num)
|
||||
// is found before num characters have been copied, destination is padded
|
||||
// with zeros until a total of num characters have been written to it.
|
||||
if (num) {
|
||||
while (--num)
|
||||
while (--num) {
|
||||
*destination++ = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
// Pointer to destination is returned.
|
||||
@@ -35,8 +36,9 @@ char *strncpy(char *destination, const char *source, size_t num)
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return 0;
|
||||
}
|
||||
while ((--n > 0) && (*s1) && (*s2) && (*s1 == *s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
@@ -74,8 +76,9 @@ char *strchr(const char *s, int ch)
|
||||
while (*s && *s != (char)ch) {
|
||||
s++;
|
||||
}
|
||||
if (*s == (char)ch)
|
||||
if (*s == (char)ch) {
|
||||
return (char *)s;
|
||||
}
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -163,8 +166,9 @@ size_t strcspn(const char *string, const char *control)
|
||||
size_t n;
|
||||
|
||||
// Clear out bit map.
|
||||
for (n = 0; n < 32; n++)
|
||||
for (n = 0; n < 32; n++) {
|
||||
map[n] = 0;
|
||||
}
|
||||
|
||||
// Set bits in control map.
|
||||
while (*ctrl) {
|
||||
@@ -192,8 +196,9 @@ char *strpbrk(const char *string, const char *control)
|
||||
int n;
|
||||
|
||||
// Clear out bit map.
|
||||
for (n = 0; n < 32; n++)
|
||||
for (n = 0; n < 32; n++) {
|
||||
map[n] = 0;
|
||||
}
|
||||
|
||||
// Set bits in control map.
|
||||
while (*ctrl) {
|
||||
@@ -317,8 +322,9 @@ char *strncat(char *s1, const char *s2, size_t n)
|
||||
s1--;
|
||||
|
||||
while (n--) {
|
||||
if (!(*s1++ = *s2++))
|
||||
if (!(*s1++ = *s2++)) {
|
||||
return start;
|
||||
}
|
||||
}
|
||||
|
||||
*s1 = '\0';
|
||||
@@ -397,11 +403,10 @@ char *strtok_r(char *str, const char *delim, char **saveptr)
|
||||
*saveptr = s;
|
||||
|
||||
// Determine if a token has been found.
|
||||
if (str == (char *)s) {
|
||||
if (str == s) {
|
||||
return NULL;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
// Intrinsic functions.
|
||||
@@ -453,7 +458,7 @@ void *memcpy(void *dst, const void *src, size_t num)
|
||||
// Initialize the content of the memory.
|
||||
while (num--) *_dst++ = *_src++;
|
||||
// Return the pointer.
|
||||
return (void *)dst;
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memccpy(void *dst, const void *src, int c, size_t n)
|
||||
@@ -625,8 +630,9 @@ char *strdup(const char *s)
|
||||
#else
|
||||
char *new = malloc(len);
|
||||
#endif
|
||||
if (new == NULL)
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new[len] = '\0';
|
||||
return (char *)memcpy(new, s, len);
|
||||
}
|
||||
@@ -639,8 +645,9 @@ char *strndup(const char *s, size_t n)
|
||||
#else
|
||||
char *new = malloc(len);
|
||||
#endif
|
||||
if (new == NULL)
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new[len] = '\0';
|
||||
return (char *)memcpy(new, s, len);
|
||||
}
|
||||
|
||||
+17
-14
@@ -4,21 +4,21 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/ipc.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/sem.h"
|
||||
#include "sys/shm.h"
|
||||
#include "sys/msg.h"
|
||||
|
||||
#include "system/syscall_types.h"
|
||||
#include "stddef.h"
|
||||
#include "string.h"
|
||||
#include "io/debug.h"
|
||||
#include "io/debug.h"
|
||||
#include "stddef.h"
|
||||
#include "stdio.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "io/debug.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/msg.h"
|
||||
#include "sys/sem.h"
|
||||
#include "sys/shm.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall3(void *, shmat, int, shmid, const void *, shmaddr, int, shmflg)
|
||||
|
||||
@@ -41,8 +41,9 @@ int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
|
||||
long __res;
|
||||
do {
|
||||
__inline_syscall4(__res, msgsnd, msqid, msgp, msgsz, msgflg);
|
||||
if (!(msgflg & IPC_NOWAIT) && (__res == -EAGAIN))
|
||||
if (!(msgflg & IPC_NOWAIT) && (__res == -EAGAIN)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while (1);
|
||||
__syscall_return(int, __res);
|
||||
@@ -53,8 +54,9 @@ ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
|
||||
long __res;
|
||||
do {
|
||||
__inline_syscall5(__res, msgrcv, msqid, msgp, msgsz, msgtyp, msgflg);
|
||||
if (!(msgflg & IPC_NOWAIT) && ((__res == -EAGAIN) || (__res == -ENOMSG)))
|
||||
if (!(msgflg & IPC_NOWAIT) && ((__res == -EAGAIN) || (__res == -ENOMSG))) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while (1);
|
||||
__syscall_return(int, __res);
|
||||
@@ -92,8 +94,9 @@ long semop(int semid, struct sembuf *sops, unsigned nsops)
|
||||
// If we get an error, the operation has been taken care of we stop
|
||||
// the loop. We also stop the loop if the operation is not allowed
|
||||
// and the IPC_NOWAIT flag is 1
|
||||
if ((__res != -EAGAIN) || (op->sem_flg & IPC_NOWAIT))
|
||||
if ((__res != -EAGAIN) || (op->sem_flg & IPC_NOWAIT)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the operation couldn't be performed and we had the IPC_NOWAIT set
|
||||
// to 1 then we return.
|
||||
|
||||
+2
-2
@@ -5,9 +5,9 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/mman.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall6(void *, mmap, void *, addr, size_t, length, int, prot, int, flags, int, fd, off_t, offset)
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "string.h"
|
||||
#include "limits.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#if 0
|
||||
#include "vfs.h"
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/utsname.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "stddef.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, uname, utsname_t *, buf)
|
||||
|
||||
+4
-4
@@ -4,9 +4,9 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "termios.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "bits/ioctls.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
int tcgetattr(int fd, termios_t *termios_p)
|
||||
{
|
||||
@@ -16,7 +16,7 @@ int tcgetattr(int fd, termios_t *termios_p)
|
||||
: "0"(__NR_ioctl), "b"((long)(fd)), "c"((long)(TCGETS)),
|
||||
"d"((long)(termios_p)));
|
||||
if (retval < 0) {
|
||||
errno = -retval;
|
||||
errno = -retval;
|
||||
retval = -1;
|
||||
}
|
||||
return retval;
|
||||
@@ -30,7 +30,7 @@ int tcsetattr(int fd, int optional_actions, const termios_t *termios_p)
|
||||
: "0"(__NR_ioctl), "b"((long)(fd)), "c"((long)(TCSETS)),
|
||||
"d"((long)(termios_p)));
|
||||
if (retval < 0) {
|
||||
errno = -retval;
|
||||
errno = -retval;
|
||||
retval = -1;
|
||||
}
|
||||
return retval;
|
||||
|
||||
+7
-7
@@ -4,10 +4,10 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "time.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
/// @brief List of week days name.
|
||||
static const char *weekdays[] = {
|
||||
@@ -23,7 +23,7 @@ static const char *months[] = {
|
||||
/// @brief Time function.
|
||||
_syscall1(time_t, time, time_t *, t)
|
||||
|
||||
time_t difftime(time_t time1, time_t time2)
|
||||
time_t difftime(time_t time1, time_t time2)
|
||||
{
|
||||
return time1 - time2;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ tm_t *localtime(const time_t *time)
|
||||
t /= 24;
|
||||
// Convert Unix time to date
|
||||
a = (unsigned int)((4 * t + 102032) / 146097 + 15);
|
||||
b = (unsigned int)(t + 2442113 + a - (a / 4));
|
||||
b = (t + 2442113 + a - (a / 4));
|
||||
c = (20 * b - 2442) / 7305;
|
||||
d = b - 365 * c - (c / 4);
|
||||
e = d * 1000 / 30601;
|
||||
@@ -383,7 +383,7 @@ size_t strftime(char *str, size_t maxsize, const char *format, const tm_t *timep
|
||||
/// @brief nanosleep function.
|
||||
_syscall2(int, nanosleep, const timespec *, req, timespec *, rem)
|
||||
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
timespec req, rem;
|
||||
req.tv_sec = seconds;
|
||||
@@ -399,4 +399,4 @@ unsigned int sleep(unsigned int seconds)
|
||||
|
||||
_syscall2(int, getitimer, int, which, itimerval *, curr_value)
|
||||
|
||||
_syscall3(int, setitimer, int, which, const itimerval *, new_value, itimerval *, old_value)
|
||||
_syscall3(int, setitimer, int, which, const itimerval *, new_value, itimerval *, old_value)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, chdir, const char *, path)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, close, int, fd)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall2(int, creat, const char *, pathname, mode_t, mode)
|
||||
|
||||
+14
-10
@@ -4,14 +4,14 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/stat.h"
|
||||
#include "fcntl.h"
|
||||
#include "io/debug.h"
|
||||
#include "stdarg.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "stdarg.h"
|
||||
#include "fcntl.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/stat.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@@ -43,7 +43,7 @@ static inline int __find_in_path(const char *file, char *buf, size_t buf_len)
|
||||
strcat(buf, file);
|
||||
if (stat(buf, &stat_buf) == 0) {
|
||||
if (stat_buf.st_mode & S_IXUSR) {
|
||||
// TODO: Check why `init` has problems with this free.
|
||||
// TODO(enrico): Check why `init` has problems with this free.
|
||||
// To reproduce the problem use this in init.c:
|
||||
// execvp("login", _argv);
|
||||
free(path);
|
||||
@@ -128,8 +128,9 @@ int execl(const char *path, const char *arg, ...)
|
||||
char *argv[argc + 1];
|
||||
va_start(ap, arg);
|
||||
argv[0] = (char *)arg;
|
||||
for (int i = 1; i <= argc; ++i)
|
||||
for (int i = 1; i <= argc; ++i) {
|
||||
argv[i] = va_arg(ap, char *);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
// Now, we can call `execve` plain and simple.
|
||||
@@ -156,8 +157,9 @@ int execlp(const char *file, const char *arg, ...)
|
||||
char *argv[argc + 1];
|
||||
va_start(ap, arg);
|
||||
argv[0] = (char *)arg;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
argv[i] = va_arg(ap, char *);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
// Close argv.
|
||||
@@ -193,8 +195,9 @@ int execle(const char *path, const char *arg, ...)
|
||||
char *argv[argc + 1];
|
||||
va_start(ap, arg);
|
||||
argv[0] = (char *)arg;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
argv[i] = va_arg(ap, char *);
|
||||
}
|
||||
// Close argv.
|
||||
argv[argc] = NULL;
|
||||
|
||||
@@ -232,8 +235,9 @@ int execlpe(const char *file, const char *arg, ...)
|
||||
char *argv[argc + 1];
|
||||
va_start(ap, arg);
|
||||
argv[0] = (char *)arg;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
argv[i] = va_arg(ap, char *);
|
||||
}
|
||||
// Close argv.
|
||||
argv[argc] = NULL;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall0(pid_t, fork)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall2(char *, getcwd, char *, buf, size_t, size)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
|
||||
_syscall3(ssize_t, getdents, int, fd, dirent_t *, dirp, unsigned int, count)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall0(pid_t, getgid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(pid_t, getpgid, pid_t, pid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall0(pid_t, getpid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall0(pid_t, getppid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(pid_t, getsid, pid_t, pid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall0(uid_t, getuid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, alarm, int, seconds)
|
||||
_syscall1(unsigned, alarm, int, seconds)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall2(int, kill, pid_t, pid, int, sig)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall3(off_t, lseek, int, fd, off_t, offset, int, whence)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall2(int, mkdir, const char *, path, mode_t, mode)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, nice, int, inc)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall3(int, open, const char *, pathname, int, flags, mode_t, mode)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, void *, arg)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, rmdir, const char *, path)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, setgid, pid_t, pid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall2(int, setpgid, pid_t, pid, pid_t, pgid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall0(pid_t, setsid)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, setuid, uid_t, pid)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
#include "signal.h"
|
||||
#include "sys/bitops.h"
|
||||
@@ -68,8 +68,9 @@ int sigaction(int signum, const sigaction_t *act, sigaction_t *oldact)
|
||||
|
||||
const char *strsignal(int sig)
|
||||
{
|
||||
if ((sig >= SIGHUP) && (sig < NSIG))
|
||||
if ((sig >= SIGHUP) && (sig < NSIG)) {
|
||||
return sys_siglist[sig - 1];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -111,7 +112,8 @@ int sigdelset(sigset_t *set, int signum)
|
||||
|
||||
int sigismember(sigset_t *set, int signum)
|
||||
{
|
||||
if (set)
|
||||
if (set) {
|
||||
return bit_check(set->sig[(signum - 1) / 32], (signum - 1) % 32);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
#include "sys/stat.h"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall1(int, unlink, const char *, path)
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "sys/wait.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/wait.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
#include "sys/errno.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
|
||||
pid_t waitpid(pid_t pid, int *status, int options)
|
||||
{
|
||||
@@ -18,15 +18,19 @@ pid_t waitpid(pid_t pid, int *status, int options)
|
||||
int __status = 0;
|
||||
do {
|
||||
__inline_syscall3(__res, waitpid, pid, &__status, options);
|
||||
if (__res < 0)
|
||||
if (__res < 0) {
|
||||
break;
|
||||
if (__status == EXIT_ZOMBIE)
|
||||
}
|
||||
if (__status == EXIT_ZOMBIE) {
|
||||
break;
|
||||
if (options && WNOHANG)
|
||||
}
|
||||
if (options && WNOHANG) {
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
if (status)
|
||||
if (status) {
|
||||
*status = __status;
|
||||
}
|
||||
__syscall_return(pid_t, __res);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall3(ssize_t, write, int, fd, const void *, buf, size_t, nbytes)
|
||||
|
||||
+37
-25
@@ -3,9 +3,9 @@
|
||||
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
|
||||
/// @brief Read formatted data from string.
|
||||
@@ -21,18 +21,19 @@ static int __vsscanf(const char *buf, const char *s, va_list ap)
|
||||
char tmp[BUFSIZ];
|
||||
|
||||
while (*s && *buf) {
|
||||
while (isspace(*s))
|
||||
while (isspace(*s)) {
|
||||
++s;
|
||||
}
|
||||
if (*s == '%') {
|
||||
++s;
|
||||
for (; *s; ++s) {
|
||||
if (strchr("dibouxcsefg%", *s))
|
||||
if (strchr("dibouxcsefg%", *s)) {
|
||||
break;
|
||||
if (*s == '*')
|
||||
}
|
||||
if (*s == '*') {
|
||||
noassign = 1;
|
||||
else if (isdigit(*s)) {
|
||||
for (tc = s; isdigit(*s); ++s)
|
||||
{}
|
||||
} else if (isdigit(*s)) {
|
||||
for (tc = s; isdigit(*s); ++s) {}
|
||||
strncpy(tmp, tc, s - tc);
|
||||
tmp[s - tc] = '\0';
|
||||
width = strtol(tmp, NULL, 10);
|
||||
@@ -40,10 +41,12 @@ static int __vsscanf(const char *buf, const char *s, va_list ap)
|
||||
}
|
||||
}
|
||||
if (*s == 's') {
|
||||
while (isspace(*buf))
|
||||
while (isspace(*buf)) {
|
||||
++buf;
|
||||
if (!width)
|
||||
}
|
||||
if (!width) {
|
||||
width = strcspn(buf, " \t\n\r\f\v");
|
||||
}
|
||||
if (!noassign) {
|
||||
char *string = va_arg(ap, char *);
|
||||
strncpy(string, buf, width);
|
||||
@@ -51,48 +54,56 @@ static int __vsscanf(const char *buf, const char *s, va_list ap)
|
||||
}
|
||||
buf += width;
|
||||
} else if (*s == 'c') {
|
||||
while (isspace(*buf))
|
||||
while (isspace(*buf)) {
|
||||
++buf;
|
||||
if (!width)
|
||||
}
|
||||
if (!width) {
|
||||
width = 1;
|
||||
}
|
||||
if (!noassign) {
|
||||
strncpy(va_arg(ap, char *), buf, width);
|
||||
}
|
||||
buf += width;
|
||||
} else if (strchr("duxob", *s)) {
|
||||
while (isspace(*buf))
|
||||
while (isspace(*buf)) {
|
||||
++buf;
|
||||
if (*s == 'd' || *s == 'u')
|
||||
}
|
||||
if (*s == 'd' || *s == 'u') {
|
||||
base = 10;
|
||||
else if (*s == 'x')
|
||||
} else if (*s == 'x') {
|
||||
base = 16;
|
||||
else if (*s == 'o')
|
||||
} else if (*s == 'o') {
|
||||
base = 8;
|
||||
else if (*s == 'b')
|
||||
} else if (*s == 'b') {
|
||||
base = 2;
|
||||
}
|
||||
if (!width) {
|
||||
if (isspace(*(s + 1)) || *(s + 1) == 0)
|
||||
if (isspace(*(s + 1)) || *(s + 1) == 0) {
|
||||
width = strcspn(buf, " \t\n\r\f\v");
|
||||
else
|
||||
} else {
|
||||
width = strchr(buf, *(s + 1)) - buf;
|
||||
}
|
||||
}
|
||||
strncpy(tmp, buf, width);
|
||||
tmp[width] = '\0';
|
||||
buf += width;
|
||||
if (!noassign)
|
||||
if (!noassign) {
|
||||
*va_arg(ap, unsigned int *) = strtol(tmp, NULL, base);
|
||||
}
|
||||
}
|
||||
if (!noassign)
|
||||
if (!noassign) {
|
||||
++count;
|
||||
}
|
||||
width = noassign = 0;
|
||||
++s;
|
||||
} else {
|
||||
while (isspace(*buf))
|
||||
while (isspace(*buf)) {
|
||||
++buf;
|
||||
if (*s != *buf)
|
||||
}
|
||||
if (*s != *buf) {
|
||||
break;
|
||||
else
|
||||
++s, ++buf;
|
||||
}
|
||||
++s, ++buf;
|
||||
}
|
||||
}
|
||||
return (count);
|
||||
@@ -109,8 +120,9 @@ static int __vfscanf(int fd, const char *fmt, va_list ap)
|
||||
int count;
|
||||
char buf[BUFSIZ + 1];
|
||||
|
||||
if (fgets(buf, BUFSIZ, fd) == 0)
|
||||
if (fgets(buf, BUFSIZ, fd) == 0) {
|
||||
return (-1);
|
||||
}
|
||||
count = __vsscanf(buf, fmt, ap);
|
||||
return (count);
|
||||
}
|
||||
|
||||
+20
-13
@@ -4,12 +4,12 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/bitops.h"
|
||||
#include "fcvt.h"
|
||||
#include "ctype.h"
|
||||
#include "string.h"
|
||||
#include "fcvt.h"
|
||||
#include "stdarg.h"
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/unistd.h"
|
||||
|
||||
/// Size of the buffer used to call cvt functions.
|
||||
@@ -35,8 +35,9 @@ static char *_upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static inline int skip_atoi(const char **s)
|
||||
{
|
||||
int i = 0;
|
||||
while (isdigit(**s))
|
||||
while (isdigit(**s)) {
|
||||
i = i * 10 + *((*s)++) - '0';
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -106,16 +107,17 @@ static char *number(char *str, long num, int base, int size, int32_t precision,
|
||||
}
|
||||
size -= precision;
|
||||
if (!bitmask_check(flags, FLAGS_ZEROPAD | FLAGS_LEFT)) {
|
||||
while (size-- > 0)
|
||||
while (size-- > 0) {
|
||||
*str++ = ' ';
|
||||
}
|
||||
}
|
||||
if (sign) {
|
||||
*str++ = sign;
|
||||
}
|
||||
if (bitmask_check(flags, FLAGS_HASH)) {
|
||||
if (base == 8)
|
||||
if (base == 8) {
|
||||
*str++ = '0';
|
||||
else if (base == 16) {
|
||||
} else if (base == 16) {
|
||||
*str++ = '0';
|
||||
*str++ = _digits[33];
|
||||
}
|
||||
@@ -377,8 +379,9 @@ static char *flt(char *str, double num, int size, int precision, char fmt, unsig
|
||||
int n, i;
|
||||
|
||||
// Left align means no zero padding.
|
||||
if (bitmask_check(flags, FLAGS_LEFT))
|
||||
if (bitmask_check(flags, FLAGS_LEFT)) {
|
||||
bitmask_clear_assign(flags, FLAGS_ZEROPAD);
|
||||
}
|
||||
|
||||
// Determine padding and sign char.
|
||||
c = bitmask_check(flags, FLAGS_ZEROPAD) ? '0' : ' ';
|
||||
@@ -589,10 +592,11 @@ int vsprintf(char *str, const char *fmt, va_list args)
|
||||
bitmask_set_assign(flags, FLAGS_UPPERCASE);
|
||||
break;
|
||||
case 'a':
|
||||
if (qualifier == 'l')
|
||||
if (qualifier == 'l') {
|
||||
tmp = eaddr(tmp, va_arg(args, unsigned char *), field_width, precision, flags);
|
||||
else
|
||||
} else {
|
||||
tmp = iaddr(tmp, va_arg(args, unsigned char *), field_width, precision, flags);
|
||||
}
|
||||
continue;
|
||||
// Integer number formats - set up the flags and "break".
|
||||
case 'o':
|
||||
@@ -621,12 +625,14 @@ int vsprintf(char *str, const char *fmt, va_list args)
|
||||
tmp = flt(tmp, va_arg(args, double), field_width, precision, *fmt, bitmask_set(flags, FLAGS_SIGN));
|
||||
continue;
|
||||
default:
|
||||
if (*fmt != '%')
|
||||
if (*fmt != '%') {
|
||||
*tmp++ = '%';
|
||||
if (*fmt)
|
||||
}
|
||||
if (*fmt) {
|
||||
*tmp++ = *fmt;
|
||||
else
|
||||
} else {
|
||||
--fmt;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -694,8 +700,9 @@ int fprintf(int fd, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
|
||||
if (len > 0) {
|
||||
if (write(fd, buffer, len) <= 0)
|
||||
if (write(fd, buffer, len) <= 0) {
|
||||
return EOF;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user