Merge branch 'master' into develop
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
SYNOPSIS
|
||||
mkdir DIRECTORY
|
||||
|
||||
DESCRIPTION
|
||||
Create the DIRECTORY, if it does not exist.
|
||||
|
||||
OPTIONS
|
||||
--help : shows command help.
|
||||
@@ -0,0 +1,8 @@
|
||||
SYNOPSIS
|
||||
rmdir DIRECTORY
|
||||
|
||||
DESCRIPTION
|
||||
Remove the DIRECTORY, if it is empty.
|
||||
|
||||
OPTIONS
|
||||
--help : shows command help.
|
||||
@@ -0,0 +1,5 @@
|
||||
SYNOPSIS
|
||||
showpid
|
||||
|
||||
DESCRIPTION
|
||||
showpid uses getppid() to print the ID of the parent process.
|
||||
+2
-16
@@ -72,21 +72,7 @@ int execv(const char *path, char *const argv[])
|
||||
|
||||
int execvp(const char *file, char *const argv[])
|
||||
{
|
||||
if (!file || !argv || !environ) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (file[0] == '/') {
|
||||
return execve(file, argv, environ);
|
||||
}
|
||||
// Prepare a buffer for the absolute path.
|
||||
char absolute_path[PATH_MAX] = { 0 };
|
||||
// Find the file inside the entries of the PATH variable.
|
||||
if (__find_in_path(file, absolute_path, PATH_MAX) == 0) {
|
||||
return execve(absolute_path, argv, environ);
|
||||
}
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
return execvpe(file, argv, environ);
|
||||
}
|
||||
|
||||
int execvpe(const char *file, char *const argv[], char *const envp[])
|
||||
@@ -95,7 +81,7 @@ int execvpe(const char *file, char *const argv[], char *const envp[])
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (file[0] == '/') {
|
||||
if (strchr(file, '/')) {
|
||||
return execve(file, argv, envp);
|
||||
}
|
||||
// Prepare a buffer for the absolute path.
|
||||
|
||||
@@ -2267,7 +2267,7 @@ static vfs_file_t *ext2_creat(const char *path, mode_t permission)
|
||||
return NULL;
|
||||
}
|
||||
// Get the parent VFS node.
|
||||
vfs_file_t *parent = vfs_open(parent_path, O_RDONLY, 0);
|
||||
vfs_file_t *parent = vfs_open(parent_path, O_WRONLY, 0);
|
||||
if (parent == NULL) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
|
||||
@@ -58,6 +58,7 @@ int sys_creat(const char *path, mode_t mode)
|
||||
|
||||
// Set the file descriptor id.
|
||||
task->fd_list[fd].file_struct = file;
|
||||
task->fd_list[fd].flags_mask = O_WRONLY|O_CREAT|O_TRUNC;
|
||||
|
||||
// Return the file descriptor and increment it.
|
||||
return fd;
|
||||
|
||||
+7
-3
@@ -18,9 +18,10 @@ static inline void print_content(const char *path, char *buffer, unsigned buflen
|
||||
// Open the file.
|
||||
int fd = open(path, O_RDONLY, 42);
|
||||
if (fd >= 0) {
|
||||
ssize_t bytes_read = 0;
|
||||
// Put on the standard output the characters.
|
||||
while (read(fd, buffer, buflen) > 0) {
|
||||
puts(buffer);
|
||||
while ((bytes_read = read(fd, buffer, buflen)) > 0) {
|
||||
write(STDOUT_FILENO, buffer, bytes_read);
|
||||
}
|
||||
// Close the file descriptor.
|
||||
close(fd);
|
||||
@@ -45,6 +46,7 @@ int main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int status = 0;
|
||||
// Prepare the buffer for reading.
|
||||
char buffer[BUFSIZ];
|
||||
// Iterate the arguments.
|
||||
@@ -60,16 +62,18 @@ int main(int argc, char **argv)
|
||||
|
||||
} else if (S_ISDIR(statbuf.st_mode)) {
|
||||
printf("cat: %s: Is a directory\n\n", argv[i]);
|
||||
status = 1;
|
||||
|
||||
} else if (S_ISLNK(statbuf.st_mode)) {
|
||||
if (readlink(argv[i], buffer, BUFSIZ)) {
|
||||
print_content(buffer, buffer, BUFSIZ);
|
||||
} else {
|
||||
printf("cat: %s: %s\n\n", argv[i], strerror(errno));
|
||||
status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
return 0;
|
||||
return status;
|
||||
}
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ static inline void print_dir_entry(dirent_t *dirent, const char *path, unsigned
|
||||
// Add a space.
|
||||
putchar(' ');
|
||||
// Print the rest.
|
||||
printf("%4d %4d %11s %2d/%2d %2d:%2d %s\n",
|
||||
printf("%4d %4d %11s %02d/%02d %02d:%02d %s\n",
|
||||
dstat.st_uid,
|
||||
dstat.st_gid,
|
||||
to_human_size(dstat.st_size),
|
||||
|
||||
+5
-16
@@ -40,6 +40,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
char *pager = "cat";
|
||||
char filepath[PATH_MAX];
|
||||
strcpy(filepath, "/usr/share/man/");
|
||||
strcat(filepath, argv[1]);
|
||||
@@ -47,23 +48,11 @@ int main(int argc, char *argv[])
|
||||
int fd = open(filepath, O_RDONLY, 42);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("%s: No manual entry for %s\n\n", argv[0], argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Prepare the buffer for reading the man file.
|
||||
char buffer[BUFSIZ];
|
||||
// Put on the standard output the characters.
|
||||
while (read(fd, buffer, BUFSIZ) > 0)
|
||||
{
|
||||
puts(buffer);
|
||||
}
|
||||
// Close the file descriptor.
|
||||
close(fd);
|
||||
// Terminate with a pair of newlines.
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
printf("%s: No manual entry for %s\n", argv[0], argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
close(fd);
|
||||
execlp(pager, pager, filepath);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user