Skip to content

Commit bc30270

Browse files
committed
Merge branch 'main' into dev/staging
2 parents 6e7034e + 2cbe2cb commit bc30270

File tree

3 files changed

+82
-36
lines changed

3 files changed

+82
-36
lines changed

file_system/file_system.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ D_File *create_directory(Path *name, uint32_t mode) {
4747
return NULL;
4848
}
4949
memcpy(new_file->name, name->path, name->length);
50+
new_file->name[name->length] = '\0';
5051
new_file->type = DIRECTORY;
5152
new_file->child = NULL;
5253
new_file->hard_links = 0;
@@ -165,6 +166,7 @@ D_File *create_directories(D_File *directory, Path path, char prevent_up) {
165166
D_File *new_dir = dandelion_alloc(sizeof(D_File), _Alignof(D_File));
166167
new_dir->type = DIRECTORY;
167168
memcpy(new_dir->name, current_path.path, current_path.length);
169+
new_dir->name[current_path.length] = '\0';
168170
new_dir->child = NULL;
169171
int error = link_file_to_folder(directory, new_dir);
170172
if (error < 0) {
@@ -408,7 +410,7 @@ int fs_initialize(int *argc, char ***argv, char ***environ) {
408410
return -1;
409411
}
410412
fs_root->name[0] = '/';
411-
fs_root->name[1] = 0;
413+
fs_root->name[1] = '\0';
412414
fs_root->type = DIRECTORY;
413415
fs_root->next = NULL;
414416
fs_root->parent = NULL;
@@ -421,7 +423,7 @@ int fs_initialize(int *argc, char ***argv, char ***environ) {
421423
dandelion_exit(ENOMEM);
422424
return -1;
423425
}
424-
memcpy(stdio_folder->name, "stdio", 6);
426+
memcpy(stdio_folder->name, "stdio\0", 7);
425427
stdio_folder->type = DIRECTORY;
426428
stdio_folder->child = NULL;
427429
stdio_folder->hard_links = 0;

file_system/paths.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,31 @@ static inline size_t namelen(const char *const name, size_t max_len) {
2323
return length;
2424
}
2525

26+
// the length parameters are the maximum length of the strings,
27+
// strings may be zero terminated earlier
2628
static inline int namecmp(const char *const name1, size_t name1_length,
2729
const char *const name2, size_t name2_length) {
2830
size_t max_length = name1_length < name2_length ? name1_length : name2_length;
29-
for (size_t index = 0; index < max_length; index++) {
30-
// this also automatically returns -1 if one of them is null terminated
31-
// earlier than their length
32-
if (name1[index] != name2[index])
33-
return name1[index] < name2[index] ? -1 : 1;
34-
// are the same if we got here
35-
if (name1[index] == '\0')
31+
size_t index = 0;
32+
for (; index < max_length; index++) {
33+
if (name1[index] == name2[index] & name1[index] != '\0')
34+
continue;
35+
// know that either they are unequal or they are now both at null
36+
// termination
37+
if (name1[index] == '\0' && name2[index] == '\0')
3638
return 0;
39+
else if (name1[index] == '\0')
40+
return -1;
41+
else if (name2[index] == '\0')
42+
return 1;
43+
else
44+
return name1[index] < name2[index] ? -1 : 1;
3745
}
3846
// they are the same until the end of the shorter one or there has not been
3947
// null termination
40-
if (name1_length < name2_length)
48+
if (name1_length < name2_length && name2[index] != '\0')
4149
return -1;
42-
else if (name2_length < name1_length)
50+
else if (name2_length < name1_length && name1[index] != '\0')
4351
return 1;
4452
else
4553
return 0;

newlib_shim/unistd.c

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <unistd.h>
33

44
// Implement functions from unistd that are not already defined in other parts
5-
// of newlibs libc Or in something we supply
5+
// of newlibs libc or in something we supply
66

77
// unsigned alarm (unsigned __secs);
88
int chdir(const char *__path) {
@@ -20,11 +20,18 @@ int chroot(const char *__path) {
2020
}
2121

2222
// int chmod (const char *__path, mode_t __mode);
23+
2324
// int chown (const char *__path, uid_t __owner, gid_t __group);
25+
2426
// int close_range (unsigned int __firstfd, unsigned int __lastfd, int
25-
// __flags); size_t confstr (int __name, char *__buf, size_t __len); char *
26-
// crypt (const char *__key, const char *__salt); char * ctermid (char *__s);
27-
// char * cuserid (char *__s);
27+
// __flags);
28+
29+
// size_t confstr (int __name, char *__buf, size_t __len);
30+
31+
// char *crypt (const char *__key, const char *__salt);
32+
33+
// char * ctermid (char *__s); char * cuserid (char *__s);
34+
2835
// int daemon (int nochdir, int noclose);
2936

3037
// function to duplicate file descriptor to second file number
@@ -60,19 +67,28 @@ int execv(const char *__path, char *const __argv[]) {
6067
}
6168
// already given in newlib
6269
// int execve (const char *__path, char * const __argv[], char * const
63-
// __envp[]); int execvp (const char *__file, char * const __argv[]); int
64-
// execvpe (const char *__file, char * const __argv[], char * const __envp[]);
70+
// __envp[]);
71+
72+
// int execvp (const char *__file, char * const __argv[]);
73+
// int execvpe (const char *__file, char * const __argv[], char * const
74+
// __envp[]);
75+
6576
// #if __ATFILE_VISIBLE
6677
// int faccessat (int __dirfd, const char *__path, int __mode, int __flags);
6778
// #endif
68-
// int fchmod (int __fildes, mode_t __mode);
69-
// int fchown (int __fildes, uid_t __owner, gid_t __group);
79+
// int fchmod (int __fildes, mode_t __mode);
80+
81+
// int fchown (int __fildes, uid_t __owner, gid_t __group);
7082
// #if __ATFILE_VISIBLE
7183
// int fchownat (int __dirfd, const char *__path, uid_t __owner, gid_t __group,
72-
// int __flags); #endif int fexecve (int __fd, char * const __argv[], char *
73-
// const __envp[]); long fpathconf (int __fd, int __name);
84+
// int __flags);
85+
// #endif
86+
// int fexecve (int __fd, char * const __argv[], char * const __envp[]);
87+
// long fpathconf (int __fd, int __name);
88+
7489
int fsync(int __fd) { return 0; }
7590
int fdatasync(int __fd) { return 0; }
91+
7692
// char * get_current_dir_name (void);
7793
char *getcwd(char *__buf, size_t __size) { return "/"; }
7894
// int getdomainname (char *__name, size_t __len);
@@ -97,27 +113,47 @@ char *getcwd(char *__buf, size_t __size) { return "/"; }
97113
// char * getwd (char *__buf);
98114
// int lchown (const char *__path, uid_t __owner, gid_t __group);
99115
// #if __ATFILE_VISIBLE
100-
// int linkat (int __dirfd1, const char *__path1, int __dirfd2, const char
101-
// *__path2, int __flags); #endif #if __MISC_VISIBLE || __XSI_VISIBLE int
102-
// nice (int __nice_value); #endif #if __MISC_VISIBLE || __XSI_VISIBLE >= 4 int
103-
// lockf (int __fd, int __cmd, off_t __len); #endif long pathconf (const char
104-
// *__path, int __name); int pause (void); #if __POSIX_VISIBLE >= 199506 int
105-
// pthread_atfork (void (*)(void), void (*)(void), void (*)(void)); #endif int
106-
// pipe (int __fildes[2]) {
116+
// int linkat (int __dirfd1, const char *__path1, int __dirfd2, const char
117+
// *__path2, int __flags);
118+
119+
// #endif #if __MISC_VISIBLE || __XSI_VISIBLE
120+
// int nice(int __nice_value);
121+
// #endif
122+
// #if __MISC_VISIBLE || __XSI_VISIBLE >= 4
123+
// int lockf(int __fd, int __cmd, off_t __len);
124+
// #endif
125+
// long pathconf (const char *__path, int __name);
126+
// int pause (void);
127+
// #if __POSIX_VISIBLE >= 199506
128+
// int pthread_atfork (void (*)(void), void (*)(void), void (*)(void));
129+
// #endif
130+
// int pipe (int __fildes[2]) {
107131
// pipe2(__fileds[2], 0);
108132
// }
109133
// int pipe2 (int __fildes[2], int flags);
110134
// #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 500
111135
// ssize_t pread (int __fd, void *__buf, size_t __nbytes, off_t __offset);
112136
// ssize_t pwrite (int __fd, const void *__buf, size_t __nbytes, off_t
113-
// __offset); #endif _READ_WRITE_RETURN_TYPE read (int __fd, void *__buf, size_t
114-
// __nbyte); #if __BSD_VISIBLE int rresvport (int *__alport); int revoke
115-
// (char *__path); #endif int rmdir (const char *__path); #if __BSD_VISIBLE
116-
// int ruserok (const char *rhost, int superuser, const char *ruser, const char
117-
// *luser); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE <
118-
// 200112) void * sbrk (ptrdiff_t __incr); #endif #if __BSD_VISIBLE ||
119-
// __POSIX_VISIBLE >= 200112 int setegid (gid_t __gid); int seteuid
120-
// (uid_t __uid); #endif int setgid (gid_t __gid);
137+
// __offset);
138+
139+
// #endif _READ_WRITE_RETURN_TYPE
140+
// read (int __fd, void *__buf, size_t __nbyte);
141+
// #if __BSD_VISIBLE
142+
// int rresvport (int *__alport);
143+
// int revoke(char *__path);
144+
// #endif
145+
// int rmdir (const char *__path);
146+
// #if __BSD_VISIBLE
147+
// int ruserok (const char *rhost, int superuser, const char *ruser, const char
148+
// *luser);
149+
// #endif
150+
// #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112)
151+
// void * sbrk (ptrdiff_t __incr);
152+
// #endif #if __BSD_VISIBLE ||__POSIX_VISIBLE >= 200112
153+
// int setegid (gid_t __gid);
154+
// int seteuid(uid_t __uid);
155+
// #endif
156+
// int setgid(gid_t __gid);
121157
int setgroups(int ngroups, const gid_t *grouplist) {
122158
*__errno() = EPERM;
123159
return -1;

0 commit comments

Comments
 (0)