-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0x00-0x02 update README to new format; add test mains
- Loading branch information
1 parent
899e381
commit b280aa3
Showing
12 changed files
with
19,506 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,129 @@ | ||
# 0x00. C - ls | ||
# (308) 0x00. C - ls | ||
Specializations > System programming & Algorithm > Linux Programming | ||
|
||
### Project author | ||
Wilfried Hennuyer | ||
|
||
### Assignment dates | ||
11-30-2020 to 12-04-2020 | ||
|
||
### Description | ||
Building a clone of the Linux function `ls`. | ||
|
||
### Requirements | ||
* Allowed Functions and System Calls | ||
* opendir (man 3 opendir) | ||
* readdir (man 3 readdir) | ||
* closedir (man 3 closedir) | ||
* exit (man 3 exit) | ||
* free (man 3 free) | ||
* lstat (man 2 lstat) | ||
* malloc (man 3 malloc) | ||
* perror (man 3 perror) | ||
* write (man 2 write) | ||
* printf (man 3 printf) | ||
* sprintf (man 3 sprintf) | ||
* fprintf (man 3 fprintf) | ||
* readlink (man 2 readlink) | ||
* ctime (man 3 ctime) | ||
* getpwuid (man 3 getpwuid) | ||
* getgrgid (man 3 getgrgid) | ||
* errno (man 3 errno) | ||
* Compiled: `gcc -Wall -Werror -Wextra -pedantic *.c -o hls` | ||
* Your program should give the same result as the real `ls`: | ||
```bash | ||
$ ls test | ||
abc BCD file file2 file3 folder1 folder2 folder3 | ||
$ ./hls test | ||
abc BCD file file2 file3 folder1 folder2 folder3 | ||
$ ls -1 | ||
abc | ||
BCD | ||
file | ||
file2 | ||
file3 | ||
folder1 | ||
folder2 | ||
folder3 | ||
hls | ||
$ ./hls -1 | ||
abc | ||
BCD | ||
file | ||
file2 | ||
file3 | ||
folder1 | ||
folder2 | ||
folder3 | ||
hls | ||
$ | ||
``` | ||
* For all tasks of this project, unless explicitly said otherwise: | ||
* You don’t have to worry about the spacing | ||
* You don’t have to worry about the sorting | ||
|
||
### Provided file(s) | ||
|
||
--- | ||
|
||
## Mandatory Tasks | ||
|
||
### :white_large_square: 0. Let's start with something simple! | ||
Create a program that lists the content of the current directory. | ||
* Usage: `hls` | ||
|
||
### :white_large_square: 1. Maybe some parameters? | ||
Your program should now take one or more file or directory names as parameters. | ||
* Usage: `hls [FILE]...` | ||
* Errors must be printed the same way than `ls` does: | ||
* In `stderr` | ||
* Starting by `<program>`: (`<program>` being `argv[0]`) | ||
* `No such file or directory`, `Permission denied`, etc… | ||
* Don’t forget the exit value | ||
|
||
### :white_large_square: 2. What about options? | ||
Implement the `-1` option. | ||
* Usage: `hls [-1] [FILE]...` | ||
* For the rest of the project, an option will be identified by a command-line argument starting with the character `-` (like `ls`). | ||
* Pay attention to “edge cases”: you should be able to handle multiple options, in any order. | ||
|
||
### :white_check_mark: 3. Hidden files | ||
Implement the `-a` option. | ||
* Usage: `hls [-a1] [FILE]...` | ||
|
||
### :white_check_mark: 4. Almost all | ||
Implement the `-A` option. | ||
* Usage: `hls [-A] [FILE]...` | ||
|
||
### :white_check_mark: 5. More details | ||
Implement the `-l` option. | ||
* Usage: `hls [-l] [FILE]...` | ||
* You might notice the `total XX` in the first line of `ls -l`. You can ignore this value for this exercise. | ||
* Pay attention to “edge cases”: Usernames and group names are not always defined. | ||
|
||
## Advanced Tasks | ||
|
||
### :white_check_mark: 6. Mixing options | ||
All options together. | ||
* Usage: `hls [-1aAl] [FILE]...` | ||
|
||
### :white_check_mark: 7. Esrever | ||
Implement the `-r` option. | ||
* Usage: `hls [-1aAlr] [FILE]...` | ||
|
||
### :white_check_mark: 8. More sorting? | ||
Implement the `-S` option. | ||
Usage: `hls [-1aAlrS] [FILE]...` | ||
|
||
### :white_check_mark: 9. I know you like sorting things. | ||
Implement the `-t` option. | ||
* Usage: `hls [-1aAlrSt] [FILE]...` | ||
|
||
### :white_check_mark: 10. The Juggernaut | ||
Implement the `-R` option. | ||
* Usage: `hls [-1aAlrStR] [FILE]...` | ||
|
||
--- | ||
|
||
## Student | ||
* **Samuel Pomeroy** - [allelomorph](github.com/allelomorph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,101 @@ | ||
# 0x01. C - Static variables, getline | ||
# (322) 0x01. C - Static variables, getline | ||
Specializations > System programming & Algorithm > Linux Programming | ||
|
||
### Project author | ||
Julien Barbier | ||
|
||
### Assignment dates | ||
12-07-2020 to 12-15-2020 | ||
|
||
### Description | ||
Introduction to static variables in C and building a clone of the glibc function `getline`. | ||
|
||
### Requirements | ||
* Allowed Functions and System Calls | ||
* `read` | ||
* `write` | ||
* `malloc` | ||
* `realloc` | ||
* `free` | ||
* `strcpy` | ||
* `strncpy` | ||
* `strcat` | ||
* `strdup` | ||
* `memset` | ||
* `memcpy` | ||
|
||
### Provided file(s) | ||
* [`man_cat`](./tests/man_cat) [`man_gcc`](./tests/man_gcc) [`the_swing`](./tests/the_swing) | ||
* [`zero`](./tests/zero) | ||
* [`0-main.c`](./tests/0-main.c) [`1-main.c`](./tests/1-main.c) [`2-main.c`](./tests/2-main.c) [`3-main.c`](./tests/3-main.c) | ||
|
||
--- | ||
|
||
## Mandatory Tasks | ||
|
||
### :white_check_mark: 0. Racing cars | ||
Write a function that keeps track of the number of laps made by several cars in a race. | ||
* Prototype: `void race_state(int *id, size_t size)` | ||
* `id` is an array of `int` representing the “identifier” of each car. | ||
* `size` is the size of this array | ||
* Each car identifier is unique | ||
* If an identifier is unknown: | ||
* Create a new car with the number of laps = 0 | ||
* Print `Car X joined the race` followed by a new line (where `X` is the identifier) | ||
* Each time the function is called: | ||
* The number of laps of each cars listed in `id` must be incremented by 1 | ||
* Print the state of the race: | ||
* Header: `Race state:` followed by a new line | ||
* For each car sorted by the identifier: `Car X [Y laps]` (where `X` is the identifier and `Y` the number of laps already done) | ||
* If your function is called with `size = 0`, you must free all allocated memory. | ||
|
||
File(s): [`laps.c`](./laps.c) [`laps.h`](./laps.h)\ | ||
Compiled: `gcc -Wall -Wextra -Werror -pedantic 0-main.c laps.c -o laps` | ||
|
||
### :white_check_mark: 1. _getline | ||
Write a function that reads an entire line from a file descriptor. | ||
* Prototype: `char *_getline(const int fd)` | ||
* Where `fd` is the file descriptor to read from | ||
* If there are no more lines to return, or if there is an error, the function should return NULL | ||
* The function returns a null-terminated string that does not include the newline character | ||
* Your header file `_getline.h` should define a macro called `READ_SIZE`. | ||
* This macro defines the number of bytes you will read each time you will call `read`: `read(fd, buffer, READ_SIZE)` | ||
* You are not allowed to read more or less than `READ_SIZE` bytes at once from `fd` | ||
* You are free to pick the value that you want for `READ_SIZE` | ||
* You can assume that `fd` will always be the same | ||
|
||
File(s): [`_getline.c`](./_getline.c) [`_getline.h`](./_getline.h)\ | ||
Compiled: `gcc -Wall -Wextra -Werror -pedantic 1-main.c _getline.c -o getline` | ||
|
||
### :white_check_mark: 2. _getline: multi-fd | ||
Handle multiple file descriptors. | ||
* When called with `-1` you should free everything and reset all your static variables | ||
|
||
File(s): [`_getline.c`](./_getline.c) [`_getline.h`](./_getline.h)\ | ||
Compiled: `gcc -Wall -Wextra -pedantic -Werror 2-main.c _getline.c -o getline` | ||
|
||
## Advanced Tasks | ||
|
||
### :white_check_mark: 3. _getline: ^@ | ||
Handle characters `\0` in lines. | ||
* Here’s the file used for the example below: [zero](./tests/zero) | ||
|
||
```bash | ||
$ cat zero | ||
line 1 Holberton..... | ||
line 2 still line 2 | ||
line 3 ......School() | ||
$ gcc -g -Wall -Wextra -pedantic 100-main.c _getline.c && ./a.out | ||
6c 69 6e 65 20 31 20 48 6f 6c 62 65 72 74 6f 6e 2e 2e 2e 2e 2e | ||
6c 69 6e 65 20 32 20 00 73 74 69 6c 6c 20 6c 69 6e 65 20 32 00 | ||
6c 69 6e 65 20 33 20 2e 2e 2e 2e 2e 2e 53 63 68 6f 6f 6c 28 29 | ||
$ | ||
``` | ||
|
||
File(s): [`_getline.c`](./_getline.c) [`_getline.h`](./_getline.h)\ | ||
Compiled: `gcc -Wall -Wextra -pedantic -Werror 100-main.c _getline.c -o getline` | ||
|
||
--- | ||
|
||
## Student | ||
* **Samuel Pomeroy** - [allelomorph](github.com/allelomorph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "laps.h" | ||
|
||
/** | ||
* main - entry point. | ||
* | ||
* Return: always 0. | ||
*/ | ||
int main() | ||
{ | ||
|
||
int ids1[3] = {1, 42, 101}; | ||
int ids2[1] = {11}; | ||
|
||
race_state(ids1, 3); | ||
printf("--\n"); | ||
race_state(ids1, 3); | ||
printf("--\n"); | ||
race_state(ids1, 3); | ||
printf("--\n"); | ||
race_state(ids2, 1); | ||
printf("--\n"); | ||
race_state(ids1, 3); | ||
printf("--\n"); | ||
race_state(ids2, 1); | ||
printf("--\n"); | ||
race_state(ids1, 3); | ||
printf("--\n"); | ||
race_state(ids2, 1); | ||
printf("--\n"); | ||
race_state(ids1, 3); | ||
printf("--\n"); | ||
race_state(ids2, 1); | ||
printf("--\n"); | ||
race_state(NULL, 0); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
#include "_getline.h" | ||
|
||
/** | ||
* main - entry point. | ||
* | ||
* Return: always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
int fd; | ||
char *line; | ||
|
||
fd = open("1-main.c", 0); | ||
while ((line = _getline(fd))) | ||
{ | ||
printf("%s\n", line); | ||
free(line); | ||
} | ||
close(fd); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
#include "_getline.h" | ||
|
||
#define LINE_LEN 21 | ||
|
||
/** | ||
* main - entry point. | ||
* | ||
* Return: always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
int fd; | ||
char *line; | ||
int i; | ||
|
||
fd = open("zero", O_RDONLY); | ||
if (-1 == fd) | ||
{ | ||
fprintf(stderr, "nop\n"); | ||
return (EXIT_FAILURE); | ||
} | ||
while ((line = _getline(fd))) | ||
{ | ||
for (i = 0; i < LINE_LEN; i++) | ||
{ | ||
if (i) | ||
{ | ||
printf(" "); | ||
} | ||
printf("%02x", line[i]); | ||
} | ||
printf("\n"); | ||
free(line); | ||
} | ||
close(fd); | ||
return (EXIT_SUCCESS); | ||
} |
Oops, something went wrong.