├── .linux ├── .github ├── .keep └── workflows │ ├── .keep │ ├── build.yml │ ├── denisgodoy_pipex-tester.yml │ ├── vfurmane_pipex-tester.yml │ ├── yoo0lh_pipex_tester_42.yml │ ├── gsilva-v_pipextester.yml │ └── norminette_v3.yml ├── .vscode ├── .keep ├── settings.json ├── c_cpp_properties.json ├── tasks.json └── launch.json ├── objects ├── .keep ├── bonus │ ├── .keep │ ├── children │ │ └── .keep │ ├── cleanup │ │ └── .keep │ ├── commands │ │ └── .keep │ ├── errors │ │ └── .keep │ ├── files │ │ └── .keep │ ├── pipes │ │ └── .keep │ └── initializers │ │ └── .keep └── mandatory │ ├── .keep │ ├── children │ └── .keep │ ├── cleanup │ └── .keep │ ├── commands │ └── .keep │ ├── errors │ └── .keep │ ├── files │ └── .keep │ ├── pipes │ └── .keep │ ├── environment │ └── .keep │ └── initializers │ └── .keep ├── scripts ├── .keep ├── github_testers.sh ├── runb.sh ├── run.sh └── compare.sh ├── tests ├── .keep └── main.c ├── archives └── .keep ├── examples ├── .keep ├── paths.c ├── execve.c └── |_execve.c ├── includes ├── .keep ├── defines.h ├── defines_bonus.h └── pipex_bonus.h ├── snippets ├── .keep ├── heredoc.sh ├── execve.c ├── char.c ├── argv.c ├── pipes.sh ├── ping_google.c ├── wait.c ├── access.c ├── <.c ├── >.c ├── envp.c ├── ping_pipe_grep_parent.c ├── ping_pipe_grep.c ├── |_parent.c ├── |.c └── error_numbers ├── sources ├── bonus │ ├── .keep │ ├── cleanup │ │ └── memory.c │ ├── pipes │ │ ├── write.c │ │ ├── file.c │ │ ├── stdin.c │ │ ├── stdout.c │ │ └── core.c │ ├── errors │ │ ├── print_error.c │ │ ├── arguments.c │ │ ├── die_2.c │ │ └── die_1.c │ ├── children │ │ ├── forks.c │ │ ├── child.c │ │ └── hdoc.c │ ├── files │ │ ├── close.c │ │ ├── open.c │ │ ├── create.c │ │ ├── open_infile.c │ │ └── create_outfile.c │ ├── commands │ │ ├── or_die.c │ │ ├── split.c │ │ ├── paths.c │ │ ├── path.c │ │ ├── find.c │ │ ├── execute.c │ │ └── tokenize.c │ ├── initializers │ │ ├── control.c │ │ ├── hdoc.c │ │ └── nex.c │ └── nex.c └── mandatory │ ├── .keep │ ├── cleanup │ └── memory.c │ ├── initializers │ ├── children.c │ ├── utils.c │ ├── fourex.c │ ├── environment.c │ ├── files.c │ ├── left.c │ └── right.c │ ├── errors │ ├── print_error.c │ ├── arguments.c │ ├── die_2.c │ └── die_1.c │ ├── files │ ├── close.c │ ├── open.c │ ├── create.c │ ├── create_outfile.c │ └── open_infile.c │ ├── commands │ ├── split.c │ ├── execute.c │ ├── find_left.c │ ├── find_right.c │ ├── loggers.c │ ├── find.c │ └── tokenize.c │ ├── fourex.c │ ├── environment │ ├── paths.c │ ├── loggers.c │ └── path.c │ ├── pipes │ ├── core.c │ └── redirections.c │ └── children │ ├── forks.c │ ├── right.c │ └── left.c ├── testers ├── denisgodoy_pipex-tester │ ├── output │ │ ├── outfile10 │ │ ├── outfile5 │ │ ├── outfile6 │ │ ├── outfile7 │ │ ├── outfile9 │ │ ├── outfile10-orig │ │ ├── outfile5-orig │ │ ├── outfile6-orig │ │ ├── outfile7-orig │ │ ├── outfile8 │ │ ├── outfile9-orig │ │ ├── outfile12 │ │ ├── outfile15 │ │ ├── outfile8-orig │ │ ├── outfile12-orig │ │ ├── outfile15-orig │ │ ├── outfile14 │ │ ├── outfile14-orig │ │ ├── valgrind11 │ │ ├── valgrind13 │ │ ├── valgrind14 │ │ ├── valgrind12 │ │ ├── valgrind15 │ │ ├── valgrind16 │ │ ├── outfile11 │ │ ├── outfile11-orig │ │ ├── outfile13 │ │ ├── outfile16 │ │ ├── outfile13-orig │ │ ├── outfile16-orig │ │ ├── valgrind3 │ │ ├── valgrind5 │ │ ├── valgrind6 │ │ ├── valgrind4 │ │ ├── valgrind7 │ │ ├── valgrind8 │ │ ├── valgrind9 │ │ └── valgrind10 │ ├── fn_used │ ├── fn_allowed │ ├── README.md │ └── Makefile ├── yoo0lh_pipex_tester_42 │ ├── pipe │ │ └── .gitkeep │ ├── test_std │ │ └── .gitkeep │ ├── img │ │ └── pipex.png │ ├── input │ └── README.md ├── vfurmane_pipex-tester │ ├── assets │ │ ├── not-executable │ │ ├── env_var │ │ ├── exit │ │ ├── banner.txt │ │ └── deepthought.txt │ ├── .gitignore │ ├── .github │ │ └── ISSUE_TEMPLATE │ │ │ └── bug_report.md │ ├── LICENSE │ ├── scripts │ │ ├── update.sh │ │ ├── config.sh │ │ └── test_utils.sh │ ├── man │ │ └── man1 │ │ │ └── pipex-tester.1 │ └── README.md └── gsilva-v_pipextester │ ├── comand_path │ ├── comand_another_path │ ├── results │ ├── test1 │ │ ├── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ │ └── outputs │ │ │ └── outpipe │ ├── test2 │ │ ├── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ │ └── outputs │ │ │ └── outpipe │ ├── test3 │ │ ├── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ │ └── outputs │ │ │ └── outpipe │ ├── test4 │ │ ├── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ │ └── outputs │ │ │ └── outpipe │ ├── test5 │ │ ├── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ │ └── outputs │ │ │ └── outpipe │ ├── test6 │ │ ├── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ │ └── outputs │ │ │ └── outpipe │ ├── testinvargs │ │ ├── outputs │ │ │ └── outpipe │ │ └── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ ├── testinvcommand │ │ ├── outputs │ │ │ └── outpipe │ │ └── exitcodes │ │ │ ├── resulpipe │ │ │ └── resulprog │ └── testinvinput │ │ ├── outputs │ │ └── outpipe │ │ └── exitcodes │ │ ├── resulpipe │ │ └── resulprog │ ├── remove.sh │ ├── infile2 │ └── Makefile ├── .normignore ├── .gitmodules ├── .gitignore ├── main.c ├── main_bonus.c └── LICENSE /.linux: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.vscode/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /archives/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /includes/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /snippets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/workflows/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sources/bonus/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sources/mandatory/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/children/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/cleanup/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/commands/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/errors/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/files/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/pipes/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/bonus/initializers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/children/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/cleanup/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/commands/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/errors/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/files/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/pipes/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/environment/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /objects/mandatory/initializers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile10: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile5: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile6: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile7: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile9: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/yoo0lh_pipex_tester_42/pipe/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/yoo0lh_pipex_tester_42/test_std/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile10-orig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile5-orig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile6-orig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile7-orig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile8: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile9-orig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/assets/not-executable: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.normignore: -------------------------------------------------------------------------------- 1 | examples/*.c 2 | snippets/*.c 3 | tests 4 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile12: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile15: -------------------------------------------------------------------------------- 1 | Hi FT 2 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile8-orig: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/comand_path: -------------------------------------------------------------------------------- 1 | /usr/bin/tr 2 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile12-orig: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile15-orig: -------------------------------------------------------------------------------- 1 | Hi FT 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/comand_another_path: -------------------------------------------------------------------------------- 1 | /usr/bin/tr 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test1/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test1/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test2/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test2/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test2/outputs/outpipe: -------------------------------------------------------------------------------- 1 | 3761 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test3/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test3/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test3/outputs/outpipe: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test4/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test4/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test4/outputs/outpipe: -------------------------------------------------------------------------------- 1 | 2585 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test5/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test5/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test6/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test6/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvargs/outputs/outpipe: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvcommand/outputs/outpipe: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvinput/outputs/outpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvargs/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvargs/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvinput/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvinput/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvcommand/exitcodes/resulpipe: -------------------------------------------------------------------------------- 1 | 127 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/testinvcommand/exitcodes/resulprog: -------------------------------------------------------------------------------- 1 | 127 2 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | config.vars 3 | outs 4 | .last-update 5 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/assets/env_var: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo $VAR1 4 | echo $VAR2 5 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/fn_used: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile14: -------------------------------------------------------------------------------- 1 | -rw rw r- 1 lgeniole lgeniole 62368 Mar 24 03:00 pipe 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/libft"] 2 | path = libs/libft 3 | url = https://github.com/librity/ft_libft 4 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile14-orig: -------------------------------------------------------------------------------- 1 | -rw rw r- 1 lgeniole lgeniole 62368 Mar 24 03:00 pipe 2 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/remove.sh: -------------------------------------------------------------------------------- 1 | rm ./results/test*/exitcodes/* 2 | rm ./results/test*/outputs/* 3 | rm ./pipex -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test5/outputs/outpipe: -------------------------------------------------------------------------------- 1 | /hbme/lgenible/cbde/ft/pipex/testers/gsilva-v_pipextester 2 | -------------------------------------------------------------------------------- /testers/yoo0lh_pipex_tester_42/img/pipex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/librity/ft_pipex/HEAD/testers/yoo0lh_pipex_tester_42/img/pipex.png -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/assets/exit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ] 4 | then 5 | exit_status=1 6 | else 7 | exit_status=$1 8 | fi 9 | 10 | exit $exit_status 11 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/infile2: -------------------------------------------------------------------------------- 1 | aaaaaaaaaaaaaaa 2 | kjd 3 | Dodosa 4 | f[affectionately 5 | cekl 6 | ec] 7 | 8 | 9 | testar tr a b ate funcionar 10 | arrumar os exit 11 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test1/outputs/outpipe: -------------------------------------------------------------------------------- 1 | ccccccccccccccc 2 | kjd 3 | Dodosc 4 | f[cffectionctely 5 | cekl 6 | ec] 7 | 8 | 9 | testcr tr c c cte funcioncr 10 | crrumcr os exit 11 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/results/test6/outputs/outpipe: -------------------------------------------------------------------------------- 1 | xxxxxxxxxxxxxxx 2 | kjd 3 | Dodosx 4 | f[xffectionxtely 5 | cekl 6 | ec] 7 | 8 | 9 | testxrxtrxxxbxxtexfuncionxr 10 | xrrumxrxosxexit 11 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/fn_allowed: -------------------------------------------------------------------------------- 1 | open 2 | access 3 | unlink 4 | close 5 | read 6 | write 7 | malloc 8 | waitpid 9 | wait 10 | free 11 | pipe 12 | dup 13 | dup2 14 | execve 15 | fork 16 | perror 17 | strerror 18 | exit 19 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/README.md: -------------------------------------------------------------------------------- 1 | # pipex-tester 2 | 3 | Clone the repo **inside your project directory**. 4 | ```shell 5 | git clone https://github.com/denisgodoy/pipex-tester 6 | cd pipex-tester 7 | ``` 8 | 9 | Run the tester with `make` 10 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/Makefile: -------------------------------------------------------------------------------- 1 | NAME := test.sh 2 | 3 | all: 4 | $(MAKE) -C ../../ all 5 | cp ../../pipex . 6 | ./$(NAME) 7 | 8 | clean: 9 | $(RM) -r output/ 10 | $(RM) infile fn_used 11 | 12 | fclean: clean 13 | $(RM) pipex 14 | 15 | re: fclean all 16 | -------------------------------------------------------------------------------- /testers/gsilva-v_pipextester/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @printf "\033[33m[Preparing test]\033[0m\n" 3 | @sleep 1 4 | @printf "\033[33m[Starting]\033[0m\n" 5 | @sleep 1 6 | @./test.sh 7 | 8 | clean: 9 | @printf "\033[31m[Cleaning last results]\033[0m\n" 10 | @./remove.sh 11 | @sleep 1 12 | @printf "\033[32m[Done!]\033[0m\n" -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.tabSize": 4, 3 | "editor.insertSpaces": false, 4 | "editor.renderWhitespace": "all", 5 | "files.trimTrailingWhitespace": true, 6 | "files.insertFinalNewline": true, 7 | "editor.detectIndentation": true, 8 | 9 | "[c]": { 10 | "editor.defaultFormatter": "keyhr.42-c-format" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind11: -------------------------------------------------------------------------------- 1 | ==111480== Memcheck, a memory error detector 2 | ==111480== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111480== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111480== Command: ./pipex infile grep\ d cat\ -e output/valgrind 5 | ==111480== Parent PID: 111309 6 | ==111480== 7 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind13: -------------------------------------------------------------------------------- 1 | ==111511== Memcheck, a memory error detector 2 | ==111511== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111511== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111511== Command: ./pipex infile cat tr\ [a-z]\ [A-Z] output/valgrind 5 | ==111511== Parent PID: 111309 6 | ==111511== 7 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind14: -------------------------------------------------------------------------------- 1 | ==111528== Memcheck, a memory error detector 2 | ==111528== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111528== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111528== Command: ./pipex infile grep\ pipex tr\ x\ '\ ' output/valgrind 5 | ==111528== Parent PID: 111309 6 | ==111528== 7 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind12: -------------------------------------------------------------------------------- 1 | ==111495== Memcheck, a memory error detector 2 | ==111495== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111495== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111495== Command: ./pipex /dev/urandom head\ -n\ 10 wc\ -l output/valgrind 5 | ==111495== Parent PID: 111309 6 | ==111495== 7 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind15: -------------------------------------------------------------------------------- 1 | ==111543== Memcheck, a memory error detector 2 | ==111543== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111543== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111543== Command: ./pipex infile echo\ 'Hi\ 42' tr\ 42\ FT output/valgrind 5 | ==111543== Parent PID: 111309 6 | ==111543== 7 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind16: -------------------------------------------------------------------------------- 1 | ==111558== Memcheck, a memory error detector 2 | ==111558== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111558== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111558== Command: ./pipex infile tr\ ex\ '\ X' tr\ pi\ 'P\ ' output/valgrind 5 | ==111558== Parent PID: 111309 6 | ==111558== 7 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile11: -------------------------------------------------------------------------------- 1 | drwxrwxr-x 3 lgeniole lgeniole 4096 Mar 24 03:00 .$ 2 | drwxrwxr-x 6 lgeniole lgeniole 4096 Mar 24 02:42 ..$ 3 | -rw-rw-r-- 1 lgeniole lgeniole 108 Feb 25 18:58 fn_allowed$ 4 | -rw-rw-r-- 1 lgeniole lgeniole 2 Mar 5 22:54 fn_used$ 5 | drwxrwxr-x 2 lgeniole lgeniole 4096 Mar 24 03:00 output$ 6 | -rw-rw-r-- 1 lgeniole lgeniole 176 Feb 25 18:58 README.md$ 7 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile11-orig: -------------------------------------------------------------------------------- 1 | drwxrwxr-x 3 lgeniole lgeniole 4096 Mar 24 03:00 .$ 2 | drwxrwxr-x 6 lgeniole lgeniole 4096 Mar 24 02:42 ..$ 3 | -rw-rw-r-- 1 lgeniole lgeniole 108 Feb 25 18:58 fn_allowed$ 4 | -rw-rw-r-- 1 lgeniole lgeniole 2 Mar 5 22:54 fn_used$ 5 | drwxrwxr-x 2 lgeniole lgeniole 4096 Mar 24 03:00 output$ 6 | -rw-rw-r-- 1 lgeniole lgeniole 176 Feb 25 18:58 README.md$ 7 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/includes", 7 | "${workspaceFolder}/libs/libft/includes", 8 | "~/.local/include" 9 | ], 10 | "defines": [], 11 | "compilerPath": "/usr/bin/gcc", 12 | "cStandard": "${default}", 13 | "cppStandard": "${default}", 14 | "intelliSenseMode": "${default}" 15 | } 16 | ], 17 | "version": 4 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "cppbuild", 6 | "label": "C/C++: gcc build active file", 7 | "command": "/usr/bin/gcc", 8 | "args": ["-g", "*.c", "-o", "a.out"], 9 | "options": { 10 | "cwd": "${workspaceFolder}/ft_printf" 11 | }, 12 | "problemMatcher": ["$gcc"], 13 | "group": { 14 | "kind": "build", 15 | "isDefault": true 16 | }, 17 | "detail": "compiler: /usr/bin/gcc" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /testers/yoo0lh_pipex_tester_42/input: -------------------------------------------------------------------------------- 1 | hello that's why we are here s, your name 2 | im not kidding 3 | what's your name 4 | please can we talk 5 | commandes are not wrking, if you want send me in private 6 | how can i reach you dud, s 7 | pelase give me a wrod that end with a 8 | oh do you mean likw palama 9 | what !!! 10 | palama 11 | sorry id don't know what this mean 12 | me too i don't know, 13 | so way you say it 14 | not your bussnis 15 | hahahahahah 16 | why you ?? 17 | i wnat it to end with s 18 | okay 19 | what bout lives 20 | emmm thats nice 21 | and eyes 22 | emmm thats batter 23 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile13: -------------------------------------------------------------------------------- 1 | TOTAL 112 2 | DRWXRWXR-X 3 LGENIOLE LGENIOLE 4096 MAR 24 03:00 . 3 | DRWXRWXR-X 6 LGENIOLE LGENIOLE 4096 MAR 24 02:42 .. 4 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 108 FEB 25 18:58 FN_ALLOWED 5 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 2 MAR 5 22:54 FN_USED 6 | -RWXRWXRWX 1 LGENIOLE LGENIOLE 0 MAR 24 03:00 INFILE 7 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 166 FEB 25 18:59 MAKEFILE 8 | DRWXRWXR-X 2 LGENIOLE LGENIOLE 4096 MAR 24 03:00 OUTPUT 9 | -RWXRWXR-X 1 LGENIOLE LGENIOLE 62368 MAR 24 03:00 PIPEX 10 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 176 FEB 25 18:58 README.MD 11 | -RWXRWXR-X 1 LGENIOLE LGENIOLE 18826 FEB 25 18:58 TEST.SH 12 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile16: -------------------------------------------------------------------------------- 1 | total 112 2 | drwXrwXr-X 3 lg n ol lg n ol 4096 Mar 24 03:00 . 3 | drwXrwXr-X 6 lg n ol lg n ol 4096 Mar 24 02:42 .. 4 | -rw-rw-r-- 1 lg n ol lg n ol 108 F b 25 18:58 fn_allow d 5 | -rw-rw-r-- 1 lg n ol lg n ol 2 Mar 5 22:54 fn_us d 6 | -rwXrwXrwX 1 lg n ol lg n ol 0 Mar 24 03:00 nf l 7 | -rw-rw-r-- 1 lg n ol lg n ol 166 F b 25 18:59 Mak f l 8 | drwXrwXr-X 2 lg n ol lg n ol 4096 Mar 24 03:00 outPut 9 | -rwXrwXr-X 1 lg n ol lg n ol 62368 Mar 24 03:00 P P X 10 | -rw-rw-r-- 1 lg n ol lg n ol 176 F b 25 18:58 README.md 11 | -rwXrwXr-X 1 lg n ol lg n ol 18826 F b 25 18:58 t st.sh 12 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/assets/banner.txt: -------------------------------------------------------------------------------- 1 | +------------------------------------------------------------------------------+ 2 | | | 3 | | | 4 | | PIPEX TESTER by vfurmane | 5 | | | 6 | | | 7 | +------------------------------------------------------------------------------+ 8 | 9 | 10 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile13-orig: -------------------------------------------------------------------------------- 1 | TOTAL 112 2 | DRWXRWXR-X 3 LGENIOLE LGENIOLE 4096 MAR 24 03:00 . 3 | DRWXRWXR-X 6 LGENIOLE LGENIOLE 4096 MAR 24 02:42 .. 4 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 108 FEB 25 18:58 FN_ALLOWED 5 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 2 MAR 5 22:54 FN_USED 6 | -RWXRWXRWX 1 LGENIOLE LGENIOLE 0 MAR 24 03:00 INFILE 7 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 166 FEB 25 18:59 MAKEFILE 8 | DRWXRWXR-X 2 LGENIOLE LGENIOLE 4096 MAR 24 03:00 OUTPUT 9 | -RWXRWXR-X 1 LGENIOLE LGENIOLE 62368 MAR 24 03:00 PIPEX 10 | -RW-RW-R-- 1 LGENIOLE LGENIOLE 176 FEB 25 18:58 README.MD 11 | -RWXRWXR-X 1 LGENIOLE LGENIOLE 18826 FEB 25 18:58 TEST.SH 12 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/outfile16-orig: -------------------------------------------------------------------------------- 1 | total 112 2 | drwXrwXr-X 3 lg n ol lg n ol 4096 Mar 24 03:00 . 3 | drwXrwXr-X 6 lg n ol lg n ol 4096 Mar 24 02:42 .. 4 | -rw-rw-r-- 1 lg n ol lg n ol 108 F b 25 18:58 fn_allow d 5 | -rw-rw-r-- 1 lg n ol lg n ol 2 Mar 5 22:54 fn_us d 6 | -rwXrwXrwX 1 lg n ol lg n ol 0 Mar 24 03:00 nf l 7 | -rw-rw-r-- 1 lg n ol lg n ol 166 F b 25 18:59 Mak f l 8 | drwXrwXr-X 2 lg n ol lg n ol 4096 Mar 24 03:00 outPut 9 | -rwXrwXr-X 1 lg n ol lg n ol 62368 Mar 24 03:00 P P X 10 | -rw-rw-r-- 1 lg n ol lg n ol 176 F b 25 18:58 README.md 11 | -rwXrwXr-X 1 lg n ol lg n ol 18826 F b 25 18:58 t st.sh 12 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind3: -------------------------------------------------------------------------------- 1 | ==111357== Memcheck, a memory error detector 2 | ==111357== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111357== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111357== Command: ./pipex infile 5 | ==111357== Parent PID: 111309 6 | ==111357== 7 | ==111357== 8 | ==111357== HEAP SUMMARY: 9 | ==111357== in use at exit: 0 bytes in 0 blocks 10 | ==111357== total heap usage: 0 allocs, 0 frees, 0 bytes allocated 11 | ==111357== 12 | ==111357== All heap blocks were freed -- no leaks are possible 13 | ==111357== 14 | ==111357== For lists of detected and suppressed errors, rerun with: -s 15 | ==111357== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help me improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Environment** 14 | List of the environment variables. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **Desktop (please complete the following information):** 23 | - OS: [e.g. Linux, Darwin, ...] 24 | - Distro (if Linux): [e.g. Debian, Arch Linux, ...] 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /testers/yoo0lh_pipex_tester_42/README.md: -------------------------------------------------------------------------------- 1 | # tester for 42 project 2 | this tester check if your pipex program work or not.
3 | >Note that the tester doesn't check the norm or leak memory 4 | ## How do i run this tester ? 5 | 6 |
git clone git@github.com:Yoo0lh/pipex_tester_42.git 
./pipex_tester.sh [mode] 7 |
8 | modes : 9 |
10 | m : mandatory
11 | b : bonus multiple pipes
12 | h : bonus here doc
13 | a : all
14 | 
15 | ### example : 16 | this example will run the tester with all parts 17 |
 ./pipex_tester a 
18 | 19 | 20 | # Contribution 21 | If you noticed something wrong with the code or if you'd like to see a new feature, you can submit an issue. If you'd like to contribute please submit a pull request. 22 | 23 | 24 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind5: -------------------------------------------------------------------------------- 1 | ==111379== Memcheck, a memory error detector 2 | ==111379== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111379== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111379== Command: ./pipex file1 cat grep\ x output/valgrind 5 | ==111379== Parent PID: 111309 6 | ==111379== 7 | ==111380== 8 | ==111380== HEAP SUMMARY: 9 | ==111380== in use at exit: 0 bytes in 0 blocks 10 | ==111380== total heap usage: 53 allocs, 53 frees, 1,158 bytes allocated 11 | ==111380== 12 | ==111380== All heap blocks were freed -- no leaks are possible 13 | ==111380== 14 | ==111380== For lists of detected and suppressed errors, rerun with: -s 15 | ==111380== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind6: -------------------------------------------------------------------------------- 1 | ==111395== Memcheck, a memory error detector 2 | ==111395== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111395== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111395== Command: ./pipex infile cat cat\ -e output/valgrind 5 | ==111395== Parent PID: 111309 6 | ==111395== 7 | ==111396== 8 | ==111396== HEAP SUMMARY: 9 | ==111396== in use at exit: 0 bytes in 0 blocks 10 | ==111396== total heap usage: 53 allocs, 53 frees, 1,158 bytes allocated 11 | ==111396== 12 | ==111396== All heap blocks were freed -- no leaks are possible 13 | ==111396== 14 | ==111396== For lists of detected and suppressed errors, rerun with: -s 15 | ==111396== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind4: -------------------------------------------------------------------------------- 1 | ==111365== Memcheck, a memory error detector 2 | ==111365== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111365== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111365== Command: ./pipex infile cat\ -e grep\ $ wc\ -l output/valgrind 5 | ==111365== Parent PID: 111309 6 | ==111365== 7 | ==111365== 8 | ==111365== HEAP SUMMARY: 9 | ==111365== in use at exit: 0 bytes in 0 blocks 10 | ==111365== total heap usage: 0 allocs, 0 frees, 0 bytes allocated 11 | ==111365== 12 | ==111365== All heap blocks were freed -- no leaks are possible 13 | ==111365== 14 | ==111365== For lists of detected and suppressed errors, rerun with: -s 15 | ==111365== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind7: -------------------------------------------------------------------------------- 1 | ==111419== Memcheck, a memory error detector 2 | ==111419== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111419== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111419== Command: ./pipex infile grep\ pipex wc\ -lw output/valgrind 5 | ==111419== Parent PID: 111309 6 | ==111419== 7 | ==111419== 8 | ==111419== HEAP SUMMARY: 9 | ==111419== in use at exit: 0 bytes in 0 blocks 10 | ==111419== total heap usage: 32 allocs, 32 frees, 669 bytes allocated 11 | ==111419== 12 | ==111419== All heap blocks were freed -- no leaks are possible 13 | ==111419== 14 | ==111419== For lists of detected and suppressed errors, rerun with: -s 15 | ==111419== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind8: -------------------------------------------------------------------------------- 1 | ==111435== Memcheck, a memory error detector 2 | ==111435== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111435== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111435== Command: ./pipex infile catzado wc\ -w output/valgrind 5 | ==111435== Parent PID: 111309 6 | ==111435== 7 | ==111436== 8 | ==111436== HEAP SUMMARY: 9 | ==111436== in use at exit: 0 bytes in 0 blocks 10 | ==111436== total heap usage: 66 allocs, 66 frees, 1,429 bytes allocated 11 | ==111436== 12 | ==111436== All heap blocks were freed -- no leaks are possible 13 | ==111436== 14 | ==111436== For lists of detected and suppressed errors, rerun with: -s 15 | ==111436== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind9: -------------------------------------------------------------------------------- 1 | ==111450== Memcheck, a memory error detector 2 | ==111450== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111450== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111450== Command: ./pipex infile cat trzero\ a\ b output/valgrind 5 | ==111450== Parent PID: 111309 6 | ==111450== 7 | ==111450== 8 | ==111450== HEAP SUMMARY: 9 | ==111450== in use at exit: 0 bytes in 0 blocks 10 | ==111450== total heap usage: 70 allocs, 70 frees, 1,465 bytes allocated 11 | ==111450== 12 | ==111450== All heap blocks were freed -- no leaks are possible 13 | ==111450== 14 | ==111450== For lists of detected and suppressed errors, rerun with: -s 15 | ==111450== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: push 4 | 5 | jobs: 6 | linter: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout project repo 10 | uses: actions/checkout@v2 11 | - name: Checkout submodules 12 | shell: bash 13 | run: | 14 | # If your submodules are configured to use SSH instead of HTTPS please uncomment the following line 15 | # git config --global url."https://github.com/".insteadOf "git@github.com:" 16 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 17 | git submodule sync --recursive 18 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 19 | - name: Build with make 20 | run: make all 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # Log files 55 | *.log 56 | 57 | # Build 58 | pipex 59 | 60 | # Tests 61 | test 62 | 63 | # Examples 64 | examples/example.c 65 | infile 66 | outfile 67 | no_permissions 68 | -------------------------------------------------------------------------------- /.github/workflows/denisgodoy_pipex-tester.yml: -------------------------------------------------------------------------------- 1 | name: denisgodoy_pipex-tester 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Checkout submodules 12 | shell: bash 13 | run: | 14 | # If your submodules are configured to use SSH instead of HTTPS please uncomment the following line 15 | # git config --global url."https://github.com/".insteadOf "git@github.com:" 16 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 17 | git submodule sync --recursive 18 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 19 | - name: Run tests 20 | run: make 21 | working-directory: ./testers/denisgodoy_pipex-tester 22 | -------------------------------------------------------------------------------- /.github/workflows/vfurmane_pipex-tester.yml: -------------------------------------------------------------------------------- 1 | name: vfurmane_pipex-tester 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Checkout submodules 12 | shell: bash 13 | run: | 14 | # If your submodules are configured to use SSH instead of HTTPS please uncomment the following line 15 | # git config --global url."https://github.com/".insteadOf "git@github.com:" 16 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 17 | git submodule sync --recursive 18 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 19 | - name: Run tests 20 | run: ./run.sh 21 | working-directory: ./testers/vfurmane_pipex-tester 22 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "(gdb) Launch", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/ft_printf/a.out", 12 | "args": [], 13 | "stopAtEntry": false, 14 | "cwd": "${workspaceFolder}/ft_printf", 15 | "environment": [], 16 | "externalConsole": false, 17 | "MIMode": "gdb", 18 | "setupCommands": [ 19 | { 20 | "description": "Enable pretty-printing for gdb", 21 | "text": "-enable-pretty-printing", 22 | "ignoreFailures": true 23 | } 24 | ] 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/yoo0lh_pipex_tester_42.yml: -------------------------------------------------------------------------------- 1 | name: yoo0lh_pipex_tester_42 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Checkout submodules 12 | shell: bash 13 | run: | 14 | # If your submodules are configured to use SSH instead of HTTPS please uncomment the following line 15 | # git config --global url."https://github.com/".insteadOf "git@github.com:" 16 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 17 | git submodule sync --recursive 18 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 19 | - name: Run tests 20 | run: ./pipex_tester.sh a 21 | working-directory: ./testers/yoo0lh_pipex_tester_42 22 | -------------------------------------------------------------------------------- /scripts/github_testers.sh: -------------------------------------------------------------------------------- 1 | # CLONE AND BUILD PROJECT 2 | cd ~ 3 | git clone --recurse-submodule https://github.com/librity/ft_pipex 4 | # git clone 42_INTRA_REPO_ADDRESS ft_pipex 5 | cd ft_pipex 6 | # norminette 7 | make norm 8 | make re 9 | 10 | # CLONE ALL GITHUB TESTERS 11 | git clone https://github.com/denisgodoy/pipex-tester tt_1 12 | git clone https://github.com/gsilva-v/PipexTester tt_2 13 | git clone https://github.com/Yoo0lh/pipex_tester_42 tt_3 14 | git clone https://github.com/vfurmane/pipex-tester tt_4 15 | chmod 777 */*.sh 16 | 17 | # RUN tt_1 18 | cd tt_1 19 | make 20 | cd .. 21 | 22 | # RUN tt_2 23 | cd tt_2 24 | ./test.sh 25 | cd .. 26 | 27 | # RUN tt_3 28 | cd tt_3 29 | ./pipex_tester.sh a 30 | cd .. 31 | 32 | # RUN tt_4 33 | cd tt_4 34 | sed -i 's/\"ping\"//g' run.sh # Remove ping 35 | # Run without timeout checks on codeserver (not necessary on ssh) 36 | # ./run.sh -t 37 | ./run.sh 38 | cd .. 39 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/assets/deepthought.txt: -------------------------------------------------------------------------------- 1 | "And you're ready to give it to us?" urged Loonquawl. 2 | "I am." 3 | "Now?" 4 | "Now," said Deep Thought. 5 | They both licked their dry lips. 6 | "Though I don't think," added Deep Thought, "that you're going to like it." 7 | "Doesn't matter!" said Phouchg. "We must know it! Now!" 8 | "Now?" inquired Deep Thought. 9 | "Yes! Now ..." 10 | "Alright," said the computer and settled into silence again. The two men fidgeted. The tension was unbearable. 11 | "You're really not going to like it," observed Deep Thought. 12 | "Tell us!" 13 | "Alright," said Deep Thought. "The Answer to the Great Question..." 14 | "Yes ...!" 15 | "Of Life, the Universe and Everything ..." said Deep Thought. 16 | "Yes ...!" 17 | "Is ..." said Deep Thought, and paused. 18 | "Yes ...!" 19 | "Is ..." 20 | "Yes ...!!!...?" 21 | "Forty-two," said Deep Thought, with infinite majesty and calm. 22 | -------------------------------------------------------------------------------- /.github/workflows/gsilva-v_pipextester.yml: -------------------------------------------------------------------------------- 1 | name: gsilva-v_pipextester 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Checkout submodules 12 | shell: bash 13 | run: | 14 | # If your submodules are configured to use SSH instead of HTTPS please uncomment the following line 15 | # git config --global url."https://github.com/".insteadOf "git@github.com:" 16 | auth_header="$(git config --local --get http.https://github.com/.extraheader)" 17 | git submodule sync --recursive 18 | git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 19 | - name: Compile 20 | run: make re 21 | - name: Copy pipex 22 | run: cp pipex ./testers/gsilva-v_pipextester 23 | - name: Run tests 24 | run: ./test.sh 25 | working-directory: ./testers/gsilva-v_pipextester 26 | -------------------------------------------------------------------------------- /sources/bonus/cleanup/memory.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* memory.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 16:14:41 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void free_memory(t_pipex *ctl) 16 | { 17 | ft_free_lalloc(&(ctl->free_me)); 18 | } 19 | -------------------------------------------------------------------------------- /sources/mandatory/cleanup/memory.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* free_memory.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 16:14:41 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/11 18:10:33 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void free_memory(t_pipex *ctl) 16 | { 17 | ft_free_lalloc(&(ctl->free_me)); 18 | } 19 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 10:34:20 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:20:59 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char **argv, char **envp) 16 | { 17 | check_argc(argc); 18 | return (fourex(argc, argv, envp)); 19 | } 20 | -------------------------------------------------------------------------------- /main_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 10:34:20 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 00:51:48 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char **argv, char **envp) 16 | { 17 | check_argc(argc); 18 | return (nex(argc, argv, envp)); 19 | } 20 | -------------------------------------------------------------------------------- /sources/bonus/pipes/write.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* write.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/25 13:47:40 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 13:53:15 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void str_to_pipe(int pipe_fds[2], char *str) 16 | { 17 | write(pipe_fds[PIPE_WRITE], str, ft_strlen(str)); 18 | } 19 | -------------------------------------------------------------------------------- /sources/mandatory/initializers/children.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* children.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/17 15:39:11 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 02:09:48 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void initialize_children(t_pipex *ctl) 16 | { 17 | initialize_right(ctl); 18 | initialize_left(ctl); 19 | } 20 | -------------------------------------------------------------------------------- /sources/mandatory/errors/print_error.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* print_error.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/10 20:48:28 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/23 15:46:12 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void print_error(char *location, char *message) 16 | { 17 | ft_printf("%s%s: %s%s\n", RB, location, message, RC); 18 | } 19 | -------------------------------------------------------------------------------- /sources/bonus/errors/print_error.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* print_error.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/10 20:48:28 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void print_error(char *location, char *message) 16 | { 17 | ft_printf("%s%s: %s%s\n", RB, location, message, RC); 18 | } 19 | -------------------------------------------------------------------------------- /sources/bonus/children/forks.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* forks.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:29:53 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 01:01:00 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | pid_t fork_or_die(void) 16 | { 17 | pid_t pid; 18 | 19 | pid = fork(); 20 | if (pid < 0) 21 | die(); 22 | return (pid); 23 | } 24 | -------------------------------------------------------------------------------- /sources/bonus/files/close.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* close.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int close_or_die(int close_me) 16 | { 17 | close_me = close(close_me); 18 | if (close_me < 0) 19 | die(); 20 | return (close_me); 21 | } 22 | -------------------------------------------------------------------------------- /sources/mandatory/files/close.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* close.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/10 18:21:01 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int close_or_die(int close_me) 16 | { 17 | close_me = close(close_me); 18 | if (close_me < 0) 19 | die(); 20 | return (close_me); 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Luis Geniole 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sources/bonus/pipes/file.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* file.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:28:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 13:52:06 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void file_to_stdin(int infile_fd) 16 | { 17 | dup2(infile_fd, STDIN_FILENO); 18 | } 19 | 20 | void stdout_to_file(int outfile_fd) 21 | { 22 | dup2(outfile_fd, STDOUT_FILENO); 23 | } 24 | -------------------------------------------------------------------------------- /.github/workflows/norminette_v3.yml: -------------------------------------------------------------------------------- 1 | name: Norminette v3 2 | 3 | on: push 4 | 5 | jobs: 6 | linter: 7 | runs-on: ubuntu-18.04 8 | steps: 9 | - name: Checkout to project repository 10 | uses: actions/checkout@v2 11 | - name: Set up Python version 12 | uses: actions/setup-python@v2 13 | with: 14 | python-version: "3.9" 15 | - name: Install norminette package 16 | run: python3 -m pip install norminette 17 | - name: Run norminette linter 18 | run: | 19 | # Runs norminette on every .c and .h file inside includes, libs and sources: 20 | find ./includes -type f \( -name \*.c -o -name \*.h \) -exec sh -c 'norminette {}' \; | tee output 21 | echo "NORM_ERRORS=$(grep -E 'Error|Warning' output | wc -l)" >> $GITHUB_ENV 22 | find ./sources -type f \( -name \*.c -o -name \*.h \) -exec sh -c 'norminette {}' \; | tee output 23 | echo "NORM_ERRORS=$(grep -E 'Error|Warning' output | wc -l)" >> $GITHUB_ENV 24 | - name: Check norminette linter result 25 | run: | 26 | echo "Norminette errors found: $NORM_ERRORS" 27 | [[ $NORM_ERRORS == 0 ]] 28 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Valentin Furmanek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sources/bonus/pipes/stdin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* stdin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:28:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 13:52:36 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void stdin_to_pipe(int pipe_fds[2]) 16 | { 17 | dup2(pipe_fds[PIPE_WRITE], STDIN_FILENO); 18 | } 19 | 20 | void pipe_to_stdin(int pipe_fds[2]) 21 | { 22 | dup2(pipe_fds[PIPE_READ], STDIN_FILENO); 23 | } 24 | -------------------------------------------------------------------------------- /sources/bonus/commands/or_die.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/24 02:09:02 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void command_or_die(t_pipex *ctl, char *raw_cmd) 16 | { 17 | char *str; 18 | 19 | str = raw_cmd; 20 | str = ft_skip_whitespace(str); 21 | if (ft_strlen(str) == 0) 22 | die_cmd(ctl, raw_cmd); 23 | } 24 | -------------------------------------------------------------------------------- /sources/bonus/commands/split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char **split_command_or_die(char *raw_command) 16 | { 17 | char **split_command; 18 | 19 | split_command = ft_split(raw_command, ' '); 20 | die_if_null(split_command); 21 | return (split_command); 22 | } 23 | -------------------------------------------------------------------------------- /sources/bonus/pipes/stdout.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* stdout.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:28:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 00:21:38 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void stdout_to_pipe(int pipe_fds[2]) 16 | { 17 | dup2(pipe_fds[PIPE_WRITE], STDOUT_FILENO); 18 | } 19 | 20 | void pipe_to_stdout(int pipe_fds[2]) 21 | { 22 | dup2(pipe_fds[PIPE_READ], STDOUT_FILENO); 23 | } 24 | -------------------------------------------------------------------------------- /sources/mandatory/commands/split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/05 20:26:52 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char **split_command_or_die(char *raw_command) 16 | { 17 | char **split_command; 18 | 19 | split_command = ft_split(raw_command, ' '); 20 | die_if_null(split_command); 21 | return (split_command); 22 | } 23 | -------------------------------------------------------------------------------- /sources/mandatory/errors/arguments.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* arguments.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/16 00:17:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 07:43:40 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void help_and_die(void) 16 | { 17 | ft_putstr(HELP_MSG); 18 | exit(EXIT_SUCCESS); 19 | } 20 | 21 | void check_argc(int argc) 22 | { 23 | if (argc == 5) 24 | return ; 25 | help_and_die(); 26 | } 27 | -------------------------------------------------------------------------------- /sources/mandatory/fourex.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* fourex.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/24 06:33:48 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 20:00:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int fourex(int argc, char **argv, char **envp) 16 | { 17 | t_pipex ctl; 18 | 19 | initialize_fourex(&ctl, argc, argv, envp); 20 | handle_left(&ctl); 21 | handle_right(&ctl); 22 | return (EXIT_SUCCESS); 23 | } 24 | -------------------------------------------------------------------------------- /sources/mandatory/initializers/utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/24 02:09:02 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 02:09:16 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void command_or_die(t_pipex *ctl, char *raw_cmd) 16 | { 17 | char *str; 18 | 19 | str = raw_cmd; 20 | str = ft_skip_whitespace(str); 21 | if (ft_strlen(str) == 0) 22 | die_cmd(ctl, raw_cmd); 23 | } 24 | -------------------------------------------------------------------------------- /sources/bonus/errors/arguments.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* arguments.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/16 00:17:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:23:04 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void help_and_die(void) 16 | { 17 | ft_putstr(HELP_MSG); 18 | exit(EXIT_SUCCESS); 19 | } 20 | 21 | void check_argc(int argc) 22 | { 23 | if (argc >= 5) 24 | return ; 25 | help_and_die(); 26 | } 27 | -------------------------------------------------------------------------------- /sources/mandatory/files/open.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* open.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/10 19:49:22 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int open_file_or_die(char *path) 16 | { 17 | int open_fd; 18 | int open_flags; 19 | 20 | open_flags = O_RDONLY; 21 | open_fd = open(path, open_flags); 22 | if (open_fd < 0) 23 | die2(path); 24 | return (open_fd); 25 | } 26 | -------------------------------------------------------------------------------- /sources/bonus/files/open.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* open.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int open_file_or_die(char *path) 16 | { 17 | int open_fd; 18 | int open_flags; 19 | 20 | open_flags = O_RDONLY; 21 | open_fd = open(path, open_flags); 22 | if (open_fd < 0) 23 | die2(path); 24 | return (open_fd); 25 | } 26 | -------------------------------------------------------------------------------- /sources/mandatory/commands/execute.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* execute.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:35:27 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/05 22:54:03 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void execute_or_die(char *command_path, char **split_cmd, char **envp) 16 | { 17 | int execve_return; 18 | 19 | execve_return = execve(command_path, split_cmd, envp); 20 | if (execve_return < 0) 21 | die2(command_path); 22 | } 23 | -------------------------------------------------------------------------------- /sources/bonus/commands/paths.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* paths.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 21:13:08 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char **get_paths_or_die(char **envp) 16 | { 17 | char *clean_path; 18 | char **paths; 19 | 20 | clean_path = get_clean_path_or_die(envp); 21 | paths = ft_split(clean_path, ':'); 22 | die_if_null(paths); 23 | return (paths); 24 | } 25 | -------------------------------------------------------------------------------- /sources/mandatory/environment/paths.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* paths.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 21:13:08 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/11 18:23:22 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char **get_paths_or_die(char **envp) 16 | { 17 | char *clean_path; 18 | char **paths; 19 | 20 | clean_path = get_clean_path_or_die(envp); 21 | paths = ft_split(clean_path, ':'); 22 | die_if_null(paths); 23 | return (paths); 24 | } 25 | -------------------------------------------------------------------------------- /testers/denisgodoy_pipex-tester/output/valgrind10: -------------------------------------------------------------------------------- 1 | ==111465== Memcheck, a memory error detector 2 | ==111465== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 3 | ==111465== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info 4 | ==111465== Command: ./pipex infile ls-l grepzao\ x output/valgrind 5 | ==111465== Parent PID: 111309 6 | ==111465== 7 | ==111465== 8 | ==111465== HEAP SUMMARY: 9 | ==111465== in use at exit: 0 bytes in 0 blocks 10 | ==111465== total heap usage: 68 allocs, 68 frees, 1,455 bytes allocated 11 | ==111465== 12 | ==111465== All heap blocks were freed -- no leaks are possible 13 | ==111465== 14 | ==111465== For lists of detected and suppressed errors, rerun with: -s 15 | ==111465== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 16 | ==111466== 17 | ==111466== HEAP SUMMARY: 18 | ==111466== in use at exit: 0 bytes in 0 blocks 19 | ==111466== total heap usage: 66 allocs, 66 frees, 1,381 bytes allocated 20 | ==111466== 21 | ==111466== All heap blocks were freed -- no leaks are possible 22 | ==111466== 23 | ==111466== For lists of detected and suppressed errors, rerun with: -s 24 | ==111466== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 25 | -------------------------------------------------------------------------------- /sources/mandatory/initializers/fourex.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* fourex.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/17 15:39:11 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 15:05:31 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void initialize_fourex(t_pipex *ctl, int argc, char **argv, char **envp) 16 | { 17 | ctl->argc = argc; 18 | ctl->argv = argv; 19 | ctl->envp = envp; 20 | ctl->free_me = NULL; 21 | pipe_or_die(ctl->pipe_fds); 22 | initialize_environment(ctl); 23 | } 24 | -------------------------------------------------------------------------------- /scripts/runb.sh: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # runb.sh :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: lpaulo-m +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/03/12 19:02:23 by lpaulo-m #+# #+# # 9 | # Updated: 2022/03/25 23:10:59 by lpaulo-m ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | make reb || exit 14 | 15 | # ./pipex 16 | ./pipex inile "grep a" "grep d" "grep s" outfile 17 | # ./pipex here_doc 33 "grep a" "grep d" outfile \ 18 | # a\ 19 | # a\ 20 | # aa\ 21 | # a\ 22 | # d\ 23 | # f\ 24 | # t\ 25 | # e\ 26 | # sf\ 27 | # \ 28 | # a\ 29 | # \ 30 | # ads\ 31 | # 33a\ 32 | # 333\ 33 | # 33 34 | -------------------------------------------------------------------------------- /snippets/heredoc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # **************************************************************************** # 4 | # # 5 | # ::: :::::::: # 6 | # heredoc.sh :+: :+: :+: # 7 | # +:+ +:+ +:+ # 8 | # By: lpaulo-m +#+ +:+ +#+ # 9 | # +#+#+#+#+#+ +#+ # 10 | # Created: 2022/02/25 18:34:17 by lpaulo-m #+# #+# # 11 | # Updated: 2022/03/08 15:10:27 by lpaulo-m ### ########.fr # 12 | # # 13 | # **************************************************************************** # 14 | 15 | # cmd1 << LIMITER | cmd2 >> outfile 16 | grep a <<33 | grep d >>outfile 17 | a 18 | a 19 | aa 20 | a 21 | d 22 | f 23 | t 24 | e 25 | sf 26 | a 27 | ads 28 | 33a 29 | 333 30 | 33 31 | 32 | grep a <>outfile 33 | a 34 | b 35 | cd 36 | af 37 | ad 38 | af 39 | fbsa 40 | k 41 | -------------------------------------------------------------------------------- /sources/bonus/initializers/control.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* control.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/26 01:01:49 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 01:02:25 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void initialize_control(t_pipex *ctl, int argc, char **argv, char **envp) 16 | { 17 | ctl->argc = argc; 18 | ctl->argv = argv; 19 | ctl->envp = envp; 20 | ctl->last_cmd = ctl->argv[ctl->argc - 2]; 21 | ctl->paths = NULL; 22 | ctl->free_me = NULL; 23 | } 24 | -------------------------------------------------------------------------------- /sources/bonus/files/create.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* create.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int create_file_or_die(char *path) 16 | { 17 | int open_fd; 18 | int create_flags; 19 | 20 | create_flags = O_CREAT | O_WRONLY | O_TRUNC; 21 | open_fd = open(path, create_flags, CREATE_PERMISSION); 22 | if (open_fd < 0) 23 | die2(path); 24 | return (open_fd); 25 | } 26 | -------------------------------------------------------------------------------- /sources/mandatory/files/create.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* create.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 01:21:20 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int create_file_or_die(char *path) 16 | { 17 | int open_fd; 18 | int create_flags; 19 | 20 | create_flags = O_CREAT | O_WRONLY | O_TRUNC; 21 | open_fd = open(path, create_flags, CREATE_PERMISSION); 22 | if (open_fd < 0) 23 | die2(path); 24 | return (open_fd); 25 | } 26 | -------------------------------------------------------------------------------- /sources/mandatory/errors/die_2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* die_2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/16 00:17:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 02:05:27 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void die5(char *location, char *message, int exit_status) 16 | { 17 | print_error(location, message); 18 | exit(exit_status); 19 | } 20 | 21 | void die_cmd(t_pipex *ctl, char *raw_cmd) 22 | { 23 | print_error(raw_cmd, ERR_NO_CMD); 24 | free_memory(ctl); 25 | exit(EKEYEXPIRED); 26 | } 27 | -------------------------------------------------------------------------------- /sources/bonus/pipes/core.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* core.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:28:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 22:53:58 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void pipe_or_die(int pipe_fds[2]) 16 | { 17 | int pipe_return; 18 | 19 | pipe_return = pipe(pipe_fds); 20 | if (pipe_return < 0) 21 | die(); 22 | } 23 | 24 | void close_pipe(int pipe_fds[2]) 25 | { 26 | close_or_die(pipe_fds[PIPE_READ]); 27 | close_or_die(pipe_fds[PIPE_WRITE]); 28 | } 29 | -------------------------------------------------------------------------------- /sources/mandatory/pipes/core.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* core.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:28:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/11 23:44:23 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void pipe_or_die(int pipe_fds[2]) 16 | { 17 | int pipe_return; 18 | 19 | pipe_return = pipe(pipe_fds); 20 | if (pipe_return < 0) 21 | die(); 22 | } 23 | 24 | void close_pipes_fds(int pipe_fds[2]) 25 | { 26 | close_or_die(pipe_fds[PIPE_READ]); 27 | close_or_die(pipe_fds[PIPE_WRITE]); 28 | } 29 | -------------------------------------------------------------------------------- /snippets/execve.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* execve.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 20:55:14 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/27 23:24:07 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc execve.c && ./a.out 14 | 15 | #include 16 | #include 17 | 18 | int main(int argc, char **argv, char **envp) 19 | { 20 | char *ls_args[] = {"-l", "-a", NULL}; 21 | 22 | printf("Main program started\n"); 23 | if (execve("/usr/bin/ls", ls_args, envp) == -1) 24 | perror("Could not execve"); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /sources/bonus/initializers/hdoc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* hdoc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/17 15:39:11 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 01:03:00 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void initialize_files(t_pipex *ctl) 16 | { 17 | ctl->outfile.path = ctl->argv[ctl->argc - 1]; 18 | ctl->outfile.fd = open_outfile_or_die(ctl); 19 | } 20 | 21 | void initialize_hdoc(t_pipex *ctl) 22 | { 23 | ctl->arg = 3; 24 | ctl->limiter = ctl->argv[2]; 25 | initialize_files(ctl); 26 | get_hdoc(ctl); 27 | } 28 | -------------------------------------------------------------------------------- /snippets/char.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* char.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 21:13:08 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/14 16:54:14 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc char.c && ./a.out 14 | 15 | #include 16 | 17 | static void explore_chars(void) 18 | { 19 | int i; 20 | 21 | i = -300; 22 | while (i < 300) 23 | { 24 | printf("|%03d|%02x|%c|\n", i, i, i); 25 | i++; 26 | } 27 | } 28 | 29 | int main(void) 30 | { 31 | printf("=============\n"); 32 | explore_chars(); 33 | printf("=============\n"); 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /sources/mandatory/commands/find_left.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* find_left.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 02:45:17 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *find_left_executable_or_die(t_pipex *ctl) 16 | { 17 | char *command_executable; 18 | 19 | command_executable = find_executable(ctl->left.cmd, ctl->paths); 20 | if (command_executable == NULL) 21 | die_cmd(ctl, ctl->left.cmd); 22 | ft_add_lalloc(&ctl->free_me, command_executable); 23 | return (command_executable); 24 | } 25 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/scripts/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | should_update() 4 | { 5 | if [ -f .last-update ] 6 | then 7 | if source .last-update 8 | then 9 | last_hour=$(echo "$(date +%s) 3600" | awk '{printf "%d", $1 - $2}') 10 | if [ $LAST_UPDATE -le $last_hour ] 11 | then 12 | return 0 13 | else 14 | return 1 15 | fi 16 | else 17 | return 1 18 | fi 19 | else 20 | return 0 21 | fi 22 | } 23 | 24 | update_tester() 25 | { 26 | git fetch origin master > /dev/null 2>&1 27 | if [ "$(git log --format='%H' -n 1 origin/master)" != "$(git log --format='%H' -n 1 master)" ] 28 | then 29 | update=-1 30 | while [ $update -ne 0 ] && [ $update -ne 1 ] 31 | do 32 | printf "Would you like to update the tester [Y/n] " 33 | nchars_opt="-N" 34 | if [[ "$OSTYPE" == "darwin"* ]] 35 | then 36 | nchars_opt="-n" 37 | fi 38 | read $nchars_opt 1 -r update 39 | [[ "$update" != $'\n' ]] && echo 40 | case "$update" in 41 | [nN]) update=0 ;; 42 | [yY$'\n']) update=1 ;; 43 | esac 44 | if [ "$update" != "0" ] && [ "$update" != "1" ] 45 | then 46 | printf "${YELLOW}Unexpected answer. Please retry...${NC}\n" 47 | update=-1 48 | fi 49 | done 50 | if [ $update -eq 1 ] 51 | then 52 | git pull --no-edit origin master 53 | fi 54 | fi 55 | } 56 | -------------------------------------------------------------------------------- /sources/mandatory/commands/find_right.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* find_right.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 02:05:44 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *find_right_executable_or_die(t_pipex *ctl) 16 | { 17 | char *command_executable; 18 | 19 | command_executable = find_executable(ctl->right.cmd, ctl->paths); 20 | if (command_executable == NULL) 21 | die_cmd(ctl, ctl->right.cmd); 22 | ft_add_lalloc(&ctl->free_me, command_executable); 23 | return (command_executable); 24 | } 25 | -------------------------------------------------------------------------------- /sources/mandatory/environment/loggers.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* loggers.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 17:15:15 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/11 18:24:56 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void log_path(t_pipex *ctl) 16 | { 17 | if (VERBOSE) 18 | ft_printf(" => PATH: \"%s\"\n", ctl->path); 19 | } 20 | 21 | void log_paths(t_pipex *ctl) 22 | { 23 | if (VERBOSE) 24 | { 25 | ft_printf(" => PATHS:\n"); 26 | ft_putstr_array(ctl->paths); 27 | ft_printf(" TOTAL: %d\n", ft_arrlen((void **)ctl->paths)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sources/mandatory/files/create_outfile.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* create_outfile.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 01:26:17 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int create_outfile_or_die(t_pipex *ctl) 16 | { 17 | int open_fd; 18 | int create_flags; 19 | 20 | create_flags = O_CREAT | O_WRONLY | O_TRUNC; 21 | open_fd = open(ctl->outfile.path, create_flags, CREATE_PERMISSION); 22 | if (open_fd < 0) 23 | { 24 | free_memory(ctl); 25 | die2(ctl->outfile.path); 26 | } 27 | return (open_fd); 28 | } 29 | -------------------------------------------------------------------------------- /sources/mandatory/initializers/environment.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* environment.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/17 15:39:11 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 01:33:55 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void set_paths(t_pipex *ctl) 16 | { 17 | ctl->paths = get_paths_or_die(ctl->envp); 18 | ft_add_lalloc_array(&ctl->free_me, (void **)ctl->paths); 19 | } 20 | 21 | void initialize_environment(t_pipex *ctl) 22 | { 23 | ctl->path = get_clean_path_or_die(ctl->envp); 24 | set_paths(ctl); 25 | log_path(ctl); 26 | log_paths(ctl); 27 | } 28 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/man/man1/pipex-tester.1: -------------------------------------------------------------------------------- 1 | .TH PIPEX-TESTER 1 "July 09, 2021" 2 | .SH NAME 3 | Pipex tester - A tester for the pipex project @42School. 4 | .SH SYNOPSYS 5 | .B ./run.sh 6 | [\fB-cltu\fR] 7 | [\fBtests_no\fR]... 8 | .SH DESCRIPTION 9 | This is a tester for the pipex project @42School. 10 | 11 | This tester was made by a student. Therefore, you should not take it as it is in defence. 12 | 13 | The tests create logs file in the \fBouts\fR folder. There are three types of file: 14 | 15 | - `test-xx.txt`: this is the outfile of pipex. 16 | 17 | - `test-xx-original.txt`: this is the outfile we would get with bash. 18 | 19 | - `test-xx-tty.txt`: this is what your program writes (`stdout` and `stderr`) 20 | 21 | - `test-xx-exit.txt`: this is the exit code of your program 22 | 23 | .SH OPTIONS 24 | .TP 25 | .BR -c 26 | Allow you to reconfigure the tester. 27 | 28 | .TP 29 | .BR -l 30 | Disable the leaks tests. 31 | 32 | .TP 33 | .BR -t 34 | Disable the timeout tests. May run the tests faster. 35 | 36 | This option is \fBdeprecated\fR since the timeout tests are now runned in background, and don't last longer than the actual test. 37 | 38 | .TP 39 | .BR -u 40 | Force the tester to update (if needed only). 41 | 42 | .SH EXIT STATUS 43 | In case of success, the tester returns 0. If at least one test doesn't pass, it returns 1. 44 | -------------------------------------------------------------------------------- /snippets/argv.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* argv.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 21:13:08 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/27 22:27:54 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc argv.c && ./a.out 14 | 15 | #include 16 | 17 | static void print_arguments(char **arguments) 18 | { 19 | int ev_count; 20 | 21 | ev_count = 0; 22 | printf("=== ARGUMENTS ===\n"); 23 | while (*arguments) 24 | { 25 | printf("%s\n", *arguments++); 26 | ev_count++; 27 | } 28 | printf("COUNT: %i\n", ev_count); 29 | } 30 | 31 | int main(int argc, char **argv, char **envp) 32 | { 33 | print_arguments(argv); 34 | } 35 | -------------------------------------------------------------------------------- /sources/bonus/children/child.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* child.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/26 00:52:57 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 01:14:35 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void handle_child(t_pipex *ctl, char *raw_cmd) 16 | { 17 | pid_t pid; 18 | int pipe[2]; 19 | 20 | pipe_or_die(pipe); 21 | pid = fork_or_die(); 22 | if (pid == CHILD_PROCESS_ID) 23 | { 24 | stdout_to_pipe(pipe); 25 | close_pipe(pipe); 26 | execute_or_die(ctl, raw_cmd); 27 | return ; 28 | } 29 | pipe_to_stdin(pipe); 30 | close_pipe(pipe); 31 | waitpid(pid, NULL, 0); 32 | } 33 | -------------------------------------------------------------------------------- /sources/bonus/initializers/nex.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* nex.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/17 15:39:11 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 01:03:15 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void initialize_files(t_pipex *ctl) 16 | { 17 | ctl->outfile.path = ctl->argv[ctl->argc - 1]; 18 | ctl->outfile.fd = create_outfile_or_die(ctl); 19 | ctl->infile.path = ctl->argv[1]; 20 | ctl->infile.fd = open_infile_or_die(ctl); 21 | file_to_stdin(ctl->infile.fd); 22 | } 23 | 24 | void initialize_nex(t_pipex *ctl) 25 | { 26 | ctl->arg = 2; 27 | initialize_files(ctl); 28 | } 29 | -------------------------------------------------------------------------------- /sources/bonus/errors/die_2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* die_2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/16 00:17:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 23:54:24 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void die5(char *location, char *message, int exit_status) 16 | { 17 | print_error(location, message); 18 | exit(exit_status); 19 | } 20 | 21 | void die6(t_pipex *ctl, char *location) 22 | { 23 | free_memory(ctl); 24 | die2(location); 25 | } 26 | 27 | void die_cmd(t_pipex *ctl, char *raw_cmd) 28 | { 29 | print_error(raw_cmd, ERR_NO_CMD); 30 | free_memory(ctl); 31 | exit(EKEYEXPIRED); 32 | } 33 | -------------------------------------------------------------------------------- /sources/mandatory/pipes/redirections.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* redirections.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:28:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/11 23:45:25 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void stdout_to_pipe(int pipe_fds[2]) 16 | { 17 | dup2(pipe_fds[PIPE_WRITE], STDOUT_FILENO); 18 | } 19 | 20 | void pipe_to_stdin(int pipe_fds[2]) 21 | { 22 | dup2(pipe_fds[PIPE_READ], STDIN_FILENO); 23 | } 24 | 25 | void file_to_stdin(int infile_fd) 26 | { 27 | dup2(infile_fd, STDIN_FILENO); 28 | } 29 | 30 | void stdout_to_file(int outfile_fd) 31 | { 32 | dup2(outfile_fd, STDOUT_FILENO); 33 | } 34 | -------------------------------------------------------------------------------- /sources/bonus/commands/path.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* path.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 21:13:08 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static char *get_clean_path(char **envp) 16 | { 17 | while (*envp) 18 | { 19 | if (ft_starts_with(*envp, PATH_PREFIX)) 20 | return (*envp + PATH_PREFIX_LENGTH); 21 | envp++; 22 | } 23 | return (NULL); 24 | } 25 | 26 | char *get_clean_path_or_die(char **envp) 27 | { 28 | char *clean_path; 29 | 30 | clean_path = get_clean_path(envp); 31 | die_if_null(clean_path); 32 | return (clean_path); 33 | } 34 | -------------------------------------------------------------------------------- /sources/mandatory/environment/path.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* path.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 21:13:08 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/23 15:46:34 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static char *get_clean_path(char **envp) 16 | { 17 | while (*envp) 18 | { 19 | if (ft_starts_with(*envp, PATH_PREFIX)) 20 | return (*envp + PATH_PREFIX_LENGTH); 21 | envp++; 22 | } 23 | return (NULL); 24 | } 25 | 26 | char *get_clean_path_or_die(char **envp) 27 | { 28 | char *clean_path; 29 | 30 | clean_path = get_clean_path(envp); 31 | die_if_null(clean_path); 32 | return (clean_path); 33 | } 34 | -------------------------------------------------------------------------------- /sources/mandatory/initializers/files.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* files.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/08 17:56:07 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 01:34:17 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void initialize_outfile(t_pipex *ctl) 16 | { 17 | ctl->outfile.path = ctl->argv[4]; 18 | ctl->outfile.fd = create_outfile_or_die(ctl); 19 | } 20 | 21 | void initialize_infile(t_pipex *ctl) 22 | { 23 | ctl->infile.path = ctl->argv[1]; 24 | ctl->infile.fd = open_infile_or_die(ctl); 25 | } 26 | 27 | void initialize_files(t_pipex *ctl) 28 | { 29 | initialize_outfile(ctl); 30 | initialize_infile(ctl); 31 | } 32 | -------------------------------------------------------------------------------- /sources/mandatory/children/forks.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* forks.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:29:53 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 01:04:27 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int fork_or_die(void) 16 | { 17 | int pid; 18 | 19 | pid = fork(); 20 | if (pid < 0) 21 | die(); 22 | return (pid); 23 | } 24 | 25 | void wait_for_left(t_pipex *ctl) 26 | { 27 | waitpid(ctl->left.pid, NULL, 0); 28 | } 29 | 30 | void wait_for_right(t_pipex *ctl) 31 | { 32 | waitpid(ctl->right.pid, NULL, 0); 33 | } 34 | 35 | void wait_for_children(t_pipex *ctl) 36 | { 37 | wait_for_left(ctl); 38 | wait_for_right(ctl); 39 | } 40 | -------------------------------------------------------------------------------- /tests/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/05 20:27:24 by aroque #+# #+# */ 9 | /* Updated: 2022/02/25 11:05:55 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "minunit.h" 14 | #include 15 | #include 16 | 17 | int x = 10; 18 | int y = 30; 19 | 20 | void setup(void) 21 | { 22 | } 23 | void teardown(void) 24 | { 25 | } 26 | 27 | MU_TEST(example) 28 | { 29 | mu_assert_int_eq(40, plus(x, y)); 30 | mu_assert_int_eq(-20, minus(x, y)); 31 | } 32 | 33 | MU_TEST_SUITE(test_suite_tokens) 34 | { 35 | MU_SUITE_CONFIGURE(&setup, &teardown); 36 | MU_RUN_TEST(example); 37 | } 38 | 39 | int main(void) 40 | { 41 | MU_RUN_SUITE(test_suite_tokens); 42 | MU_REPORT(); 43 | return (MU_EXIT_CODE); 44 | } 45 | -------------------------------------------------------------------------------- /sources/mandatory/children/right.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* right.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 20:08:13 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 02:32:08 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void redirect_descriptors(t_pipex *ctl) 16 | { 17 | stdout_to_file(ctl->outfile.fd); 18 | pipe_to_stdin(ctl->pipe_fds); 19 | close_pipes_fds(ctl->pipe_fds); 20 | close_or_die(ctl->outfile.fd); 21 | } 22 | 23 | static void initialize(t_pipex *ctl) 24 | { 25 | initialize_outfile(ctl); 26 | initialize_right(ctl); 27 | } 28 | 29 | void handle_right(t_pipex *ctl) 30 | { 31 | initialize(ctl); 32 | redirect_descriptors(ctl); 33 | execute_or_die(ctl->right.path, ctl->right.tokens, ctl->envp); 34 | free_memory(ctl); 35 | } 36 | -------------------------------------------------------------------------------- /sources/mandatory/commands/loggers.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* loggers.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 17:15:15 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 14:07:01 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void log_command(char *command_executable, char **flags) 16 | { 17 | if (VERBOSE) 18 | { 19 | ft_printf(" => EXECUTABLE: %s\n", command_executable); 20 | ft_printf(" => FLAGS:\n"); 21 | ft_putstr_array(flags); 22 | ft_printf(" TOTAL: %d\n", ft_arrlen((void **)flags)); 23 | } 24 | } 25 | 26 | void log_fourex(t_pipex *ctl) 27 | { 28 | if (VERBOSE) 29 | ft_printf( 30 | " => Executing \"< %s %s | %s > %s\"\n", 31 | ctl->infile.path, 32 | ctl->left.raw, 33 | ctl->right.raw, 34 | ctl->outfile.path); 35 | } 36 | -------------------------------------------------------------------------------- /sources/mandatory/initializers/left.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* left.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/17 15:39:11 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 22:04:16 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void set_tokens(t_pipex *ctl) 16 | { 17 | ctl->left.tokens = tokenize_or_die(ctl->left.raw); 18 | ft_add_lalloc_array(&ctl->free_me, (void **)ctl->left.tokens); 19 | } 20 | 21 | void initialize_left(t_pipex *ctl) 22 | { 23 | ctl->left.raw = ctl->argv[2]; 24 | command_or_die(ctl, ctl->left.raw); 25 | set_tokens(ctl); 26 | ctl->left.cmd = ctl->left.tokens[0]; 27 | ctl->left.path = find_left_executable_or_die(ctl); 28 | ctl->left.flags = ctl->left.tokens + 1; 29 | log_command(ctl->left.path, ctl->left.flags); 30 | } 31 | -------------------------------------------------------------------------------- /sources/mandatory/initializers/right.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* right.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/17 15:39:11 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 22:04:21 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void set_tokens(t_pipex *ctl) 16 | { 17 | ctl->right.tokens = tokenize_or_die(ctl->right.raw); 18 | ft_add_lalloc_array(&ctl->free_me, (void **)ctl->right.tokens); 19 | } 20 | 21 | void initialize_right(t_pipex *ctl) 22 | { 23 | ctl->right.raw = ctl->argv[3]; 24 | command_or_die(ctl, ctl->right.raw); 25 | set_tokens(ctl); 26 | ctl->right.cmd = ctl->right.tokens[0]; 27 | ctl->right.path = find_right_executable_or_die(ctl); 28 | ctl->right.flags = ctl->right.tokens + 1; 29 | log_command(ctl->right.path, ctl->right.flags); 30 | } 31 | -------------------------------------------------------------------------------- /sources/mandatory/children/left.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* left.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 20:08:04 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 02:30:37 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void redirect_descriptors(t_pipex *ctl) 16 | { 17 | file_to_stdin(ctl->infile.fd); 18 | stdout_to_pipe(ctl->pipe_fds); 19 | close_pipes_fds(ctl->pipe_fds); 20 | close_or_die(ctl->infile.fd); 21 | } 22 | 23 | static void initialize(t_pipex *ctl) 24 | { 25 | initialize_left(ctl); 26 | initialize_infile(ctl); 27 | } 28 | 29 | void handle_left(t_pipex *ctl) 30 | { 31 | ctl->left.pid = fork_or_die(); 32 | if (ctl->left.pid != CHILD_PROCESS_ID) 33 | return ; 34 | initialize(ctl); 35 | redirect_descriptors(ctl); 36 | execute_or_die(ctl->left.path, ctl->left.tokens, ctl->envp); 37 | free_memory(ctl); 38 | } 39 | -------------------------------------------------------------------------------- /sources/bonus/errors/die_1.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* die_1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/16 00:17:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void die_if_null(void *ptr) 16 | { 17 | if (ptr == NULL) 18 | die2(ERR_NULL_POINTER); 19 | } 20 | 21 | void die(void) 22 | { 23 | perror(ERR_GENERIC_RED); 24 | ft_putstr(RC); 25 | exit(EXIT_FAILURE); 26 | } 27 | 28 | void die2(char *location) 29 | { 30 | ft_putstr(RB); 31 | perror(location); 32 | ft_putstr(RC); 33 | exit(EXIT_FAILURE); 34 | } 35 | 36 | void die3(char *location, int exit_status) 37 | { 38 | ft_putstr(RB); 39 | perror(location); 40 | ft_putstr(RC); 41 | exit(exit_status); 42 | } 43 | 44 | void die4(int exit_status) 45 | { 46 | perror(ERR_GENERIC_RED); 47 | ft_putstr(RC); 48 | exit(exit_status); 49 | } 50 | -------------------------------------------------------------------------------- /sources/mandatory/errors/die_1.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* die_1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/16 00:17:03 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/23 15:45:45 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void die_if_null(void *ptr) 16 | { 17 | if (ptr == NULL) 18 | die2(ERR_NULL_POINTER); 19 | } 20 | 21 | void die(void) 22 | { 23 | perror(ERR_GENERIC_RED); 24 | ft_putstr(RC); 25 | exit(EXIT_FAILURE); 26 | } 27 | 28 | void die2(char *location) 29 | { 30 | ft_putstr(RB); 31 | perror(location); 32 | ft_putstr(RC); 33 | exit(EXIT_FAILURE); 34 | } 35 | 36 | void die3(char *location, int exit_status) 37 | { 38 | ft_putstr(RB); 39 | perror(location); 40 | ft_putstr(RC); 41 | exit(exit_status); 42 | } 43 | 44 | void die4(int exit_status) 45 | { 46 | perror(ERR_GENERIC_RED); 47 | ft_putstr(RC); 48 | exit(exit_status); 49 | } 50 | -------------------------------------------------------------------------------- /sources/bonus/files/open_infile.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* open_infile.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void exists_or_die(t_pipex *ctl) 16 | { 17 | int exists; 18 | 19 | exists = access(ctl->infile.path, F_OK); 20 | if (exists < 0) 21 | { 22 | free_memory(ctl); 23 | die3(ctl->infile.path, EXIT_FAILURE); 24 | } 25 | } 26 | 27 | static void read_or_die(t_pipex *ctl) 28 | { 29 | int can_read; 30 | 31 | can_read = access(ctl->infile.path, R_OK); 32 | if (can_read < 0) 33 | { 34 | free_memory(ctl); 35 | die3(ctl->infile.path, EXIT_SUCCESS); 36 | } 37 | } 38 | 39 | int open_infile_or_die(t_pipex *ctl) 40 | { 41 | exists_or_die(ctl); 42 | read_or_die(ctl); 43 | return (open_file_or_die(ctl->infile.path)); 44 | } 45 | -------------------------------------------------------------------------------- /sources/mandatory/files/open_infile.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* open_infile.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/11 23:59:39 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void exists_or_die(t_pipex *ctl) 16 | { 17 | int exists; 18 | 19 | exists = access(ctl->infile.path, F_OK); 20 | if (exists < 0) 21 | { 22 | free_memory(ctl); 23 | die3(ctl->infile.path, EXIT_FAILURE); 24 | } 25 | } 26 | 27 | static void read_or_die(t_pipex *ctl) 28 | { 29 | int can_read; 30 | 31 | can_read = access(ctl->infile.path, R_OK); 32 | if (can_read < 0) 33 | { 34 | free_memory(ctl); 35 | die3(ctl->infile.path, EXIT_SUCCESS); 36 | } 37 | } 38 | 39 | int open_infile_or_die(t_pipex *ctl) 40 | { 41 | exists_or_die(ctl); 42 | read_or_die(ctl); 43 | return (open_file_or_die(ctl->infile.path)); 44 | } 45 | -------------------------------------------------------------------------------- /snippets/pipes.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # **************************************************************************** # 4 | # # 5 | # ::: :::::::: # 6 | # pipes.sh :+: :+: :+: # 7 | # +:+ +:+ +:+ # 8 | # By: lpaulo-m +#+ +:+ +#+ # 9 | # +#+#+#+#+#+ +#+ # 10 | # Created: 2022/02/25 18:34:17 by lpaulo-m #+# #+# # 11 | # Updated: 2022/03/06 00:01:52 by lpaulo-m ### ########.fr # 12 | # # 13 | # **************************************************************************** # 14 | 15 | < infile ls | wc > outfile; echo $?; cat outfile 16 | 17 | < infile ls -l | wc -l > outfile; echo $?; cat outfile 18 | < infile grep a1 | wc -w > outfile; echo $?; cat outfile 19 | 20 | < .gitignore tr a b | tr b c > outfile; echo $?; cat outfile 21 | < EOF tr a b | tr b c > outfile; echo $?; cat outfile 22 | < .gitignore ping 8.8.8.8 | grep ms > outfile; echo $?; cat outfile 23 | 24 | echo "DIFFERENT EXIT CODES" 25 | < bad cat | grep x > outfile; echo $? 26 | < bad grep x | cat > outfile; echo $? 27 | 28 | echo "RUNS LAST COMMAND DESPITE ERROR" 29 | < infile notexisting | wc > outfile; echo $? 30 | < infile catzado | wc -w > outfile ; echo $? ; cat outfile 31 | -------------------------------------------------------------------------------- /sources/bonus/files/create_outfile.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* create_outfile.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 22:04:01 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 17:56:41 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int create_outfile_or_die(t_pipex *ctl) 16 | { 17 | int open_fd; 18 | int flags; 19 | 20 | flags = O_CREAT | O_WRONLY | O_TRUNC; 21 | open_fd = open(ctl->outfile.path, flags, CREATE_PERMISSION); 22 | if (open_fd < 0) 23 | { 24 | free_memory(ctl); 25 | die2(ctl->outfile.path); 26 | } 27 | return (open_fd); 28 | } 29 | 30 | int open_outfile_or_die(t_pipex *ctl) 31 | { 32 | int open_fd; 33 | int flags; 34 | 35 | flags = O_CREAT | O_WRONLY | O_APPEND; 36 | open_fd = open(ctl->outfile.path, flags, CREATE_PERMISSION); 37 | if (open_fd < 0) 38 | { 39 | free_memory(ctl); 40 | die2(ctl->outfile.path); 41 | } 42 | return (open_fd); 43 | } 44 | -------------------------------------------------------------------------------- /snippets/ping_google.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ping_google.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 23:21:12 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/28 22:35:47 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc ping_google.c && ./a.out 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | #define CHILD_PROCESS_ID 0 22 | 23 | static void die(void) 24 | { 25 | perror("\033[0;31mERROR!\033[0m"); 26 | exit(EXIT_FAILURE); 27 | } 28 | 29 | static void ping_google(void) 30 | { 31 | execlp("ping", "ping", "-c", "5", "google.com", NULL); 32 | } 33 | 34 | int main(int argc, char **argv) 35 | { 36 | int pipe_descriptors[2]; 37 | int ping_pid; 38 | 39 | if (pipe(pipe_descriptors) == -1) 40 | die(); 41 | 42 | ping_pid = fork(); 43 | if (ping_pid < 0) 44 | die(); 45 | 46 | if (ping_pid == CHILD_PROCESS_ID) 47 | ping_google(); 48 | waitpid(ping_pid, NULL, 0); 49 | 50 | return (EXIT_SUCCESS); 51 | } 52 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/scripts/config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | prompt_configuration() 4 | { 5 | printf "\t${BOLD}Configuration${NC}\n\n" 6 | printf "The project directory (default: ../pipex): " 7 | read project_directory 8 | if [ -z "$project_directory" ] 9 | then 10 | project_directory="../pipex" 11 | fi 12 | if [ -z "$project_directory" ] 13 | then 14 | project_directory="../pipex" 15 | fi 16 | printf "\n" 17 | printf "Would you like to check for updates on run ?\nThis option is recommended as the tester is still actively updated\n" 18 | check_update=-1 19 | while [ $check_update -ne 0 ] && [ $check_update -ne 1 ] 20 | do 21 | printf "Check for update on run [Y/n] " 22 | nchars_opt="-N" 23 | if [[ "$OSTYPE" == "darwin"* ]] 24 | then 25 | nchars_opt="-n" 26 | fi 27 | read $nchars_opt 1 -r check_update 28 | [[ "$check_update" != $'\n' ]] && echo 29 | case "$check_update" in 30 | [nN]) check_update=0 ;; 31 | [yY$'\n']) check_update=1 ;; 32 | esac 33 | if [ "$check_update" != "0" ] && [ "$check_update" != "1" ] 34 | then 35 | printf "${YELLOW}Unexpected answer. Please retry...${NC}\n" 36 | check_update=-1 37 | fi 38 | done 39 | 40 | if ! touch config.vars > /dev/null 2>&1 && ! [ -w config.vars ] 41 | then 42 | printf "${YELLOW}Unable to create the configuration file as your user...${NC}\n" 43 | PROJECT_DIRECTORY=$project_directory 44 | CHECK_UPDATE=$check_update 45 | READ_CONFIG=0 46 | else 47 | echo "# This file was automatically generated by the pipex-tester" > config.vars 48 | echo "# https://github.com/vfurmane/pipex-tester" >> config.vars 49 | echo >> config.vars 50 | echo "PROJECT_DIRECTORY='$project_directory'" >> config.vars 51 | echo "CHECK_UPDATE=$check_update" >> config.vars 52 | fi 53 | } 54 | -------------------------------------------------------------------------------- /examples/paths.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* paths.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 20:55:14 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/02 01:41:03 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void print_paths(char **paths) 16 | { 17 | int paths_count; 18 | 19 | paths_count = 0; 20 | ft_printf(" => PATHS:\n"); 21 | while(*paths) 22 | { 23 | ft_printf(" \"%s\"\n", *paths++); 24 | paths_count++; 25 | } 26 | ft_printf(" TOTAL: %d\n", paths_count); 27 | } 28 | 29 | void free_string_array(char **free_me) 30 | { 31 | char **free_me_too; 32 | 33 | free_me_too = free_me; 34 | while(*free_me) 35 | free(*free_me++); 36 | free(free_me_too); 37 | } 38 | 39 | int main(int argc, char **argv, char **envp) 40 | { 41 | char *clean_path; 42 | char **paths; 43 | 44 | clean_path = get_clean_path_or_die(envp); 45 | ft_printf(" => PATH: \"%s\"\n", clean_path); 46 | 47 | paths = ft_split(clean_path, ':'); 48 | print_paths(paths); 49 | free_string_array(paths); 50 | 51 | return (EXIT_SUCCESS); 52 | } 53 | -------------------------------------------------------------------------------- /sources/bonus/children/hdoc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* hdoc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/25 22:47:21 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 14:40:57 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void get_hdoc_stream(t_pipex *ctl, int pipe[2]) 16 | { 17 | int status; 18 | char *line; 19 | 20 | while (true) 21 | { 22 | ft_putstr(HDOC_FEED); 23 | status = ft_get_next_line(STDIN_FILENO, &line); 24 | if (status == GNL_ERROR) 25 | die2(ERR_GNL); 26 | if (ft_streq(line, ctl->limiter)) 27 | { 28 | free(line); 29 | free_memory(ctl); 30 | exit(EXIT_SUCCESS); 31 | } 32 | line = ft_strjoin_free(line, "\n"); 33 | str_to_pipe(pipe, line); 34 | free(line); 35 | } 36 | } 37 | 38 | void get_hdoc(t_pipex *ctl) 39 | { 40 | pid_t pid; 41 | int pipe[2]; 42 | 43 | pipe_or_die(pipe); 44 | pid = fork_or_die(); 45 | if (pid != CHILD_PROCESS_ID) 46 | { 47 | get_hdoc_stream(ctl, pipe); 48 | return ; 49 | } 50 | pipe_to_stdin(pipe); 51 | close_pipe(pipe); 52 | wait(NULL); 53 | } 54 | -------------------------------------------------------------------------------- /sources/mandatory/commands/find.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* find.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/10 18:43:50 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static char *build_executable_path(char *path, char *command) 16 | { 17 | char *executable; 18 | 19 | executable = ft_strjoin(path, "/"); 20 | executable = ft_strjoin_free(executable, command); 21 | return (executable); 22 | } 23 | 24 | char *find_executable(char *command, char **paths) 25 | { 26 | char *executable; 27 | int can_execute; 28 | 29 | while (*paths) 30 | { 31 | executable = build_executable_path(*paths, command); 32 | can_execute = access(executable, X_OK); 33 | if (can_execute == 0) 34 | return (executable); 35 | free(executable); 36 | paths++; 37 | } 38 | return (NULL); 39 | } 40 | 41 | char *find_executable_or_die(char *command, char **paths) 42 | { 43 | char *command_executable; 44 | 45 | command_executable = find_executable(command, paths); 46 | if (command_executable == NULL) 47 | die5(command, "command not found", EXIT_FAILURE); 48 | return (command_executable); 49 | } 50 | -------------------------------------------------------------------------------- /sources/bonus/commands/find.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* find.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static char *build_executable_path(char *path, char *command) 16 | { 17 | char *executable; 18 | 19 | executable = ft_strjoin(path, "/"); 20 | executable = ft_strjoin_free(executable, command); 21 | return (executable); 22 | } 23 | 24 | char *find_executable(char *command, char **paths) 25 | { 26 | char *executable; 27 | int can_execute; 28 | 29 | while (*paths) 30 | { 31 | executable = build_executable_path(*paths, command); 32 | can_execute = access(executable, X_OK); 33 | if (can_execute == 0) 34 | return (executable); 35 | free(executable); 36 | paths++; 37 | } 38 | return (NULL); 39 | } 40 | 41 | char *find_executable_or_die(char *command, char **paths) 42 | { 43 | char *command_executable; 44 | 45 | command_executable = find_executable(command, paths); 46 | if (command_executable == NULL) 47 | die5(command, "command not found", EXIT_FAILURE); 48 | return (command_executable); 49 | } 50 | -------------------------------------------------------------------------------- /sources/bonus/nex.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* nex.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/24 06:33:48 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 01:13:32 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void initialize(t_pipex *ctl, int argc, char **argv, char **envp) 16 | { 17 | initialize_control(ctl, argc, argv, envp); 18 | if (ft_starts_with(ctl->argv[1], HDOC_IDENTIFIER)) 19 | initialize_hdoc(ctl); 20 | else 21 | initialize_nex(ctl); 22 | } 23 | 24 | static void handle_children(t_pipex *ctl) 25 | { 26 | int children_count; 27 | char *child_cmd; 28 | 29 | children_count = ctl->argc - 2; 30 | while (ctl->arg < children_count) 31 | { 32 | child_cmd = ctl->argv[ctl->arg++]; 33 | handle_child(ctl, child_cmd); 34 | } 35 | } 36 | 37 | static void run_last_cmd(t_pipex *ctl) 38 | { 39 | stdout_to_file(ctl->outfile.fd); 40 | execute_or_die(ctl, ctl->last_cmd); 41 | } 42 | 43 | int nex(int argc, char **argv, char **envp) 44 | { 45 | t_pipex ctl; 46 | 47 | initialize(&ctl, argc, argv, envp); 48 | handle_children(&ctl); 49 | run_last_cmd(&ctl); 50 | free_memory(&ctl); 51 | return (EXIT_SUCCESS); 52 | } 53 | -------------------------------------------------------------------------------- /sources/bonus/commands/execute.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* execute.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/01 19:35:27 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 00:37:44 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void initialize_environment(t_pipex *ctl) 16 | { 17 | if (ctl->paths != NULL) 18 | return ; 19 | ctl->path = get_clean_path_or_die(ctl->envp); 20 | ctl->paths = get_paths_or_die(ctl->envp); 21 | ft_add_lalloc_array(&ctl->free_me, (void **)ctl->paths); 22 | } 23 | 24 | static void initialize_execute(t_pipex *ctl, char *raw_cmd, t_exec *ex) 25 | { 26 | command_or_die(ctl, raw_cmd); 27 | ex->tokens = tokenize_or_die(raw_cmd); 28 | ft_add_lalloc_array(&ctl->free_me, (void **)ex->tokens); 29 | ex->cmd = ex->tokens[0]; 30 | ex->path = find_executable(ex->cmd, ctl->paths); 31 | if (ex->path == NULL) 32 | die_cmd(ctl, ex->cmd); 33 | ft_add_lalloc(&ctl->free_me, ex->path); 34 | } 35 | 36 | void execute_or_die(t_pipex *ctl, char *raw_cmd) 37 | { 38 | t_exec ex; 39 | 40 | initialize_environment(ctl); 41 | initialize_execute(ctl, raw_cmd, &ex); 42 | ex.code = execve(ex.path, ex.tokens, ctl->envp); 43 | if (ex.code < 0) 44 | die6(ctl, ex.path); 45 | } 46 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/scripts/test_utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wait_for_timeout() 4 | { 5 | sleep 2 6 | if kill -0 $1 > /dev/null 2>&1 7 | then 8 | kill $1 9 | fi 10 | } 11 | 12 | pipex_test() 13 | { 14 | if [ $DISABLE_TIMEOUT -eq 0 ] 15 | then 16 | $MEMLEAKS "$@" & 17 | bg_process=$! 18 | wait_for_timeout $bg_process & 19 | wait $bg_process 20 | else 21 | "$@" 22 | fi 23 | status_code=$? 24 | return $status_code 25 | } 26 | 27 | pipex_verbose() 28 | { 29 | if [ $VERBOSE -gt 0 ] && ([ "$result" != "OK" ] || [ "$result_color" != "$GREEN" ]) 30 | then 31 | [ -f outs/test-$num.txt ] && echo "Your pipex:" && cat outs/test-$num.txt 32 | [ -f outs/test-$num-original.txt ] && echo "Bash:" && cat outs/test-$num-original.txt 33 | [ -f outs/test-$num-tty.txt ] && echo "Your tty output:" && cat outs/test-$num-tty.txt 34 | [ -f outs/test-$num-exit.txt ] && echo "Your exit status:" && cat outs/test-$num-exit.txt 35 | fi 36 | } 37 | 38 | pipex_summary() 39 | { 40 | exec 1>&3 41 | printf "\n\n" 42 | printf "\t${BOLD}Summary${NC}\n\n" > /dev/stdout 43 | 44 | [ $TESTS_OK -gt 0 ] && printf "${GREEN}$TESTS_OK OK${NC}" 45 | [ $TESTS_OK -gt 0 ] && [ $TESTS_KO -gt 0 ] && printf " - " 46 | [ $TESTS_KO -gt 0 ] && printf "${RED}$TESTS_KO KO${NC}" 47 | ([ $TESTS_OK -gt 0 ] || [ $TESTS_KO -gt 0 ]) && [ $TESTS_LK -gt 0 ] && printf " - " 48 | [ $TESTS_LK -gt 0 ] && printf "${RED}$TESTS_LK LK${NC}" 49 | ([ $TESTS_OK -gt 0 ] || [ $TESTS_KO -gt 0 ] || [ $TESTS_LK -gt 0 ]) && [ $TESTS_TO -gt 0 ] && printf " - " 50 | [ $TESTS_TO -gt 0 ] && printf "${RED}$TESTS_TO TO${NC}" 51 | printf "\n\n" 52 | 53 | printf "${GREEN}OK${NC}: Test passed\n" 54 | printf "${YELLOW}OK${NC}: Not optimal or like bash (should not invalidate the project)\n" 55 | printf "${RED}KO${NC}: Test did not pass\n" 56 | printf "${RED}LK${NC}: Test detected leaks\n" 57 | printf "${RED}TO${NC}: Test timed out\n" 58 | 59 | if [ $TESTS_KO -eq 0 ] && [ $TESTS_LK -eq 0 ] && [ $TESTS_TO -eq 0 ] 60 | then 61 | exit 0 62 | else 63 | exit 1 64 | fi 65 | } 66 | -------------------------------------------------------------------------------- /scripts/run.sh: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # run.sh :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: lpaulo-m +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/03/12 19:02:23 by lpaulo-m #+# #+# # 9 | # Updated: 2022/03/26 10:16:15 by lpaulo-m ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | make re || exit 14 | 15 | #./pipex infile "ls" "wc" outfile; echo $? ; cat outfile 16 | #./pipex infile "cat" "wc" outfile; echo $? ; cat outfile 17 | #./pipex infile "cat -E" "wc -l" outfile; echo $? ; cat outfile 18 | #./pipex infile "cat -E" "wc -m" outfile; echo $? ; cat outfile 19 | #./pipex infile "ls -l" "wc -l" outfile; echo $? ; cat outfile 20 | #./pipex infile "ls -l -a -s" "wc -l" outfile; echo $? ; cat outfile 21 | #./pipex infile "ls -l -a -s" "wc -m" outfile; echo $? ; cat outfile 22 | #./pipex infile "grep a" "wc -w" outfile; echo $? ; cat outfile 23 | #./pipex .gitignore "tr a b" "tr b c" outfile; echo $? ; cat outfile 24 | #./pipex EOF "tr a b" "tr b c" outfile; echo $? ; cat outfile 25 | #./pipex .gitignore "ping 8.8.8.8" "grep ms" outfile; echo $? ; cat outfile 26 | #./pipex .gitignore "tr x ' '" "tr i ' '" outfile; echo $? ; cat outfile 27 | #./pipex .gitignore "tr ex ' X'" "tr pi 'P '" outfile; echo $? ; cat outfile 28 | ./pipex infile "tr a ' '" "tr ' ' x" outfile; echo $? ; cat outfile 29 | #./pipex infile "notexisting" "wc" outfile; echo $? ; cat outfile 30 | #./pipex infile "catzado" "wc -w" outfile; echo $? ; cat outfile 31 | -------------------------------------------------------------------------------- /examples/execve.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* execve.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 20:55:14 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/05 22:54:06 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void static_cleanup(char *command, char **paths, char **split_cmd) 16 | { 17 | free(command); 18 | ft_free_string_array(paths); 19 | ft_free_string_array(split_cmd); 20 | } 21 | 22 | static void handle_command(char *command_executable, char **split_cmd, char **envp) 23 | { 24 | int fork_pid; 25 | 26 | fork_pid = fork_or_die(); 27 | if (fork_pid != CHILD_PROCESS_ID) 28 | return ; 29 | execute_or_die(command_executable, split_cmd, envp); 30 | } 31 | 32 | int main(int argc, char **argv, char **envp) 33 | { 34 | char **paths; 35 | char *raw_command; 36 | char **split_cmd; 37 | char **flags; 38 | char *command; 39 | char *command_executable; 40 | 41 | raw_command = "ls -l -a -s"; 42 | paths = get_paths_or_die(envp); 43 | split_cmd = split_command_or_die(raw_command); 44 | command = split_cmd[0]; 45 | flags = split_cmd + 1; 46 | 47 | if (ft_strlen(command) == 0) 48 | die2("NO COMMAND"); 49 | 50 | command_executable = find_executable_or_die(command, paths); 51 | log_command(command_executable, flags); 52 | handle_command(command_executable, split_cmd, envp); 53 | 54 | static_cleanup(command_executable, paths, split_cmd); 55 | return (EXIT_SUCCESS); 56 | } 57 | -------------------------------------------------------------------------------- /sources/bonus/commands/tokenize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* tokenize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 19:12:30 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void subvert_spaces(char *str) 16 | { 17 | str = ft_strchr(str, '\''); 18 | while (str != NULL && *str != '\0') 19 | { 20 | str++; 21 | while (*str != '\'' && *str != '\0') 22 | { 23 | if (*str == ' ') 24 | *str = NOT_ASCII; 25 | str++; 26 | } 27 | if (*str == '\'') 28 | str++; 29 | } 30 | } 31 | 32 | static void remove_quotes(char *str) 33 | { 34 | str = ft_strchr(str, '\''); 35 | while (str != NULL) 36 | { 37 | ft_strcpy(str, str + 1); 38 | str = ft_strchr(str, '\''); 39 | } 40 | } 41 | 42 | static void restore_spaces(char **tokens) 43 | { 44 | char *token; 45 | 46 | while (*tokens != NULL) 47 | { 48 | token = *tokens; 49 | while (*token != '\0') 50 | { 51 | if (*token == NOT_ASCII) 52 | *token = ' '; 53 | token++; 54 | } 55 | tokens++; 56 | } 57 | } 58 | 59 | char **tokenize_or_die(char *raw_cmd) 60 | { 61 | char *free_me; 62 | char **tokens; 63 | 64 | if (ft_strchr(raw_cmd, '\'') == NULL) 65 | return (split_command_or_die(raw_cmd)); 66 | free_me = ft_strdup(raw_cmd); 67 | subvert_spaces(free_me); 68 | remove_quotes(free_me); 69 | tokens = split_command_or_die(free_me); 70 | restore_spaces(tokens); 71 | free(free_me); 72 | return (tokens); 73 | } 74 | -------------------------------------------------------------------------------- /sources/mandatory/commands/tokenize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* tokenize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/05 20:21:05 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 01:59:13 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static void subvert_spaces(char *str) 16 | { 17 | str = ft_strchr(str, '\''); 18 | while (str != NULL && *str != '\0') 19 | { 20 | str++; 21 | while (*str != '\'' && *str != '\0') 22 | { 23 | if (*str == ' ') 24 | *str = NOT_ASCII; 25 | str++; 26 | } 27 | if (*str == '\'') 28 | str++; 29 | } 30 | } 31 | 32 | static void remove_quotes(char *str) 33 | { 34 | str = ft_strchr(str, '\''); 35 | while (str != NULL) 36 | { 37 | ft_strcpy(str, str + 1); 38 | str = ft_strchr(str, '\''); 39 | } 40 | } 41 | 42 | static void restore_spaces(char **tokens) 43 | { 44 | char *token; 45 | 46 | while (*tokens != NULL) 47 | { 48 | token = *tokens; 49 | while (*token != '\0') 50 | { 51 | if (*token == NOT_ASCII) 52 | *token = ' '; 53 | token++; 54 | } 55 | tokens++; 56 | } 57 | } 58 | 59 | char **tokenize_or_die(char *raw_cmd) 60 | { 61 | char *free_me; 62 | char **tokens; 63 | 64 | if (ft_strchr(raw_cmd, '\'') == NULL) 65 | return (split_command_or_die(raw_cmd)); 66 | free_me = ft_strdup(raw_cmd); 67 | subvert_spaces(free_me); 68 | remove_quotes(free_me); 69 | tokens = split_command_or_die(free_me); 70 | restore_spaces(tokens); 71 | free(free_me); 72 | return (tokens); 73 | } 74 | -------------------------------------------------------------------------------- /snippets/wait.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* wait.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/03/25 22:45:31 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/25 22:46:57 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc wait.c && ./a.out 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | int wstatus; 24 | pid_t cpid, w; 25 | 26 | cpid = fork(); 27 | if (cpid == -1) 28 | { 29 | perror("fork"); 30 | exit(EXIT_FAILURE); 31 | } 32 | if (cpid == 0) 33 | { /* Code executed by child */ 34 | printf("Child PID is %jd\n", (intmax_t)getpid()); 35 | if (argc == 1) 36 | pause(); /* Wait for signals */ 37 | _exit(atoi(argv[1])); 38 | } 39 | else 40 | { /* Code executed by parent */ 41 | do 42 | { 43 | w = waitpid(cpid, &wstatus, WUNTRACED | WCONTINUED); 44 | if (w == -1) 45 | { 46 | perror("waitpid"); 47 | exit(EXIT_FAILURE); 48 | } 49 | if (WIFEXITED(wstatus)) 50 | { 51 | printf("exited, status=%d\n", WEXITSTATUS(wstatus)); 52 | } 53 | else if (WIFSIGNALED(wstatus)) 54 | { 55 | printf("killed by signal %d\n", WTERMSIG(wstatus)); 56 | } 57 | else if (WIFSTOPPED(wstatus)) 58 | { 59 | printf("stopped by signal %d\n", WSTOPSIG(wstatus)); 60 | } 61 | else if (WIFCONTINUED(wstatus)) 62 | { 63 | printf("continued\n"); 64 | } 65 | } while (!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus)); 66 | exit(EXIT_SUCCESS); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /includes/defines.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* defines.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 18:20:45 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/24 08:00:59 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DEFINES_H 14 | # define DEFINES_H 15 | 16 | # define VERBOSE 0 17 | 18 | # define CHILD_PROCESS_ID 0 19 | 20 | # define PIPE_READ 0 21 | # define PIPE_WRITE 1 22 | 23 | # define CREATE_PERMISSION 0000664 24 | 25 | # define PATH_PREFIX "PATH=" 26 | # define PATH_PREFIX_LENGTH 5 27 | 28 | # define NOT_ASCII -42 29 | 30 | /******************************************************************************\ 31 | * MESSAGES 32 | \******************************************************************************/ 33 | 34 | # define HELP_MSG "Welcome to lpaulo-m's pipex!\n\ 35 | \n\ 36 | USAGE:\n\ 37 | ./pipex file1 \"cmd1\" \"cmd2\" file2\n\ 38 | behaves like: < file1 cmd1 | cmd2 > file2\n\ 39 | \n\ 40 | EXAMPLES:\n\ 41 | ./pipex infile \"ls -l\" \"wc -l\" outfile\n\ 42 | ./pipex infile \"grep a1\" \"wc -w\" outfile\n\ 43 | \n\ 44 | " 45 | 46 | /******************************************************************************\ 47 | * ERRORS 48 | \******************************************************************************/ 49 | 50 | # define EXIT_SUCCESS_STR "0\n" 51 | # define EXIT_FAILURE_STR "1\n" 52 | 53 | # define EKEYEXPIRED 127 54 | # define EKEYEXPIRED_STR "127\n" 55 | 56 | # define ERR_GENERIC_RED "\033[0;31mERROR" 57 | # define ERR_NULL_POINTER "ERROR: critical null pointer" 58 | # define ERR_NO_CMD "command not found" 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /testers/vfurmane_pipex-tester/README.md: -------------------------------------------------------------------------------- 1 | # Pipex Tester 2 | 3 | This repo provides test scripts for your **pipex** project @42School. 4 | 5 | > Note that the tester doesn't check the norm. The purpose of this repo is to be more effective in evaluation, not to botch it up. 6 | 7 | > Furthermore, the tester is absolutely not official and many tests may be irrelevant. It is intended for helping you design your project. Please do not use it as an absolute reference during defense. 8 | 9 | ## Installation 10 | 11 | First things first, clone this repo (the preferred path is alongside the **pipex**'s directory). 12 | 13 | ```shell 14 | git clone https://github.com/vfurmane/pipex-tester 15 | ``` 16 | 17 | ## Usage 18 | 19 | ```shell 20 | ./run.sh [-cltu] [tests_no]... 21 | ``` 22 | 23 | Once the installation is done, `cd` into the tester's directory, and run the `./run.sh` script. You should be prompted some configuration questions. If you have answered any of them incorrectly, you can execute `./run.sh -c` or `./run.sh --config` to be prompted the questions again. 24 | 25 | To stop the tester earlier, you can press Ctrl-C, and it will show you your grade at that moment. 26 | 27 | The logs are stored in the `outs` directory. You'll find three types of file: 28 | 29 | - `test-xx.txt`: this is the outfile of pipex. 30 | - `test-xx-original.txt`: this is the outfile we would get with bash. 31 | - `test-xx-tty.txt`: this is what your program writes (`stdout` and `stderr`) 32 | - `test-xx-exit.txt`: this is the exit code of your program 33 | 34 | You may find files like that `test-xx.x.txt`. These are log files for command executed twice during the same test. 35 | 36 | There is a man page for the tester: 37 | 38 | ```shell 39 | man ./man/man1/pipex-tester.1 40 | ``` 41 | 42 | ### Arguments 43 | 44 | #### test number 45 | 46 | Run the specified tests. 47 | 48 | ```shell 49 | ./run.sh 1 2 3 50 | ``` 51 | 52 | #### -c 53 | 54 | Allow you to reconfigure the tester. 55 | 56 | ```shell 57 | ./run.sh -c 58 | ``` 59 | 60 | #### -l 61 | 62 | Disable the leaks tests. 63 | 64 | ```shell 65 | ./run.sh -l 66 | ``` 67 | 68 | #### -t 69 | 70 | Disable the timeout tests. May run the tests faster. 71 | 72 | ```shell 73 | ./run.sh -t 74 | ``` 75 | 76 | #### -u 77 | 78 | Force the tester to update (if needed only). 79 | 80 | ```shell 81 | ./run.sh -u 82 | ``` 83 | 84 | ## Troubleshooting 85 | 86 | If you encounter another problem, please feel free to open an Issue using the **GitHub**'s tab. 87 | -------------------------------------------------------------------------------- /snippets/access.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* access.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 20:55:14 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/02 01:02:06 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc access.c && ./a.out 14 | 15 | #include 16 | #include 17 | 18 | static void putstr(char *s) 19 | { 20 | if (s == NULL) 21 | return ; 22 | while (*s) 23 | write(1, (s++), 1); 24 | } 25 | 26 | static void handle_error(char *file, int access_result) 27 | { 28 | if (access_result < 0) 29 | { 30 | putstr(" ===> "); 31 | perror(file); 32 | } 33 | } 34 | 35 | static void test_access(char *file) 36 | { 37 | int access_result; 38 | 39 | // TEST IF FILE EXISTS 40 | printf("\n=== %s ===\n", file); 41 | access_result = access(file, F_OK); 42 | printf(" F_OK: %i\n", access_result); 43 | handle_error(file, access_result); 44 | 45 | // TEST READ PERMISSION 46 | access_result = access(file, R_OK); 47 | printf(" R_OK: %i\n", access_result); 48 | handle_error(file, access_result); 49 | 50 | // TEST WRITE PERMISSION 51 | access_result = access(file, W_OK); 52 | printf(" W_OK: %i\n", access_result); 53 | handle_error(file, access_result); 54 | 55 | // TEST EXECUTE PERMISSION 56 | access_result = access(file, X_OK); 57 | printf(" X_OK: %i\n", access_result); 58 | handle_error(file, access_result); 59 | 60 | // TEST ALL PERMISSIONS 61 | access_result = access(file, F_OK | R_OK | W_OK | X_OK); 62 | printf(" ALL FLAGS: %i\n", access_result); 63 | handle_error(file, access_result); 64 | } 65 | 66 | int main(int argc, char **argv, char **envp) 67 | { 68 | test_access("/usr/bin/ls"); 69 | test_access("infile"); 70 | test_access("outfile"); 71 | test_access("no_permissions"); 72 | 73 | return (0); 74 | } 75 | -------------------------------------------------------------------------------- /snippets/<.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* <.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/28 22:20:29 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/28 22:35:47 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc "<.c" && ./a.out infile "wc" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define CHILD_PROCESS_ID 0 22 | #define OPEN_FLAGS O_RDONLY 23 | 24 | static void die(void) 25 | { 26 | perror("\033[0;31mERROR!\033[0m"); 27 | exit(EXIT_FAILURE); 28 | } 29 | 30 | static int open_file_or_die(char *filename) 31 | { 32 | int open_fd; 33 | 34 | open_fd = open(filename, OPEN_FLAGS); 35 | if (open_fd < 0) 36 | die(); 37 | return (open_fd); 38 | } 39 | 40 | static int close_file_or_die(int close_fd) 41 | { 42 | close_fd = close(close_fd); 43 | if (close_fd < 0) 44 | die(); 45 | return (close_fd); 46 | } 47 | 48 | static void file_to_stdin(int infile_fd) 49 | { 50 | dup2(infile_fd, STDIN_FILENO); 51 | } 52 | 53 | static void execute_no_args(char *command) 54 | { 55 | execlp(command, command, NULL); 56 | } 57 | 58 | static void handle_arguments( 59 | int argc, 60 | char **argv, 61 | char **infile, 62 | char **command) 63 | { 64 | if (argc != 3) 65 | die(); 66 | *infile = argv[1]; 67 | *command = argv[2]; 68 | printf("excuting \"< %s %s\"\n", *infile, *command); 69 | } 70 | 71 | int main(int argc, char **argv, char **envp) 72 | { 73 | char *infile; 74 | int infile_fd; 75 | char *command; 76 | 77 | handle_arguments(argc, argv, &infile, &command); 78 | 79 | infile_fd = open_file_or_die(infile); 80 | file_to_stdin(infile_fd); 81 | execute_no_args(command); 82 | 83 | close_file_or_die(infile_fd); 84 | return (EXIT_SUCCESS); 85 | } 86 | -------------------------------------------------------------------------------- /snippets/>.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* >.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 23:21:12 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/28 22:35:47 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc ">.c" && ./a.out "ls" outfile 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define CHILD_PROCESS_ID 0 22 | #define CREATE_FLAGS O_CREAT|O_WRONLY|O_TRUNC 23 | #define CREATE_PERMISSION 0000664 24 | 25 | static void die(void) 26 | { 27 | perror("\033[0;31mERROR!\033[0m"); 28 | exit(EXIT_FAILURE); 29 | } 30 | 31 | static int create_file_or_die(char *filename) 32 | { 33 | int open_fd; 34 | 35 | open_fd = open(filename, CREATE_FLAGS, CREATE_PERMISSION); 36 | if (open_fd < 0) 37 | die(); 38 | return (open_fd); 39 | } 40 | 41 | static int close_file_or_die(int close_fd) 42 | { 43 | close_fd = close(close_fd); 44 | if (close_fd < 0) 45 | die(); 46 | return (close_fd); 47 | } 48 | 49 | static void stdout_to_file(int outfile_fd) 50 | { 51 | dup2(outfile_fd, STDOUT_FILENO); 52 | } 53 | 54 | static void execute_no_args(char *command) 55 | { 56 | execlp(command, command, NULL); 57 | } 58 | 59 | static void handle_arguments( 60 | int argc, 61 | char **argv, 62 | char **command, 63 | char **outfile) 64 | { 65 | if (argc != 3) 66 | die(); 67 | *command = argv[1]; 68 | *outfile = argv[2]; 69 | printf("excuting \"%s > %s\"\n", *command, *outfile); 70 | } 71 | 72 | int main(int argc, char **argv, char **envp) 73 | { 74 | char *command; 75 | char *outfile; 76 | int outfile_fd; 77 | 78 | handle_arguments(argc, argv, &command, &outfile); 79 | 80 | outfile_fd = create_file_or_die(outfile); 81 | stdout_to_file(outfile_fd); 82 | execute_no_args(command); 83 | 84 | close_file_or_die(outfile_fd); 85 | return (EXIT_SUCCESS); 86 | } 87 | -------------------------------------------------------------------------------- /snippets/envp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* envp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/27 21:13:08 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/28 13:34:20 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc envp.c && ./a.out 14 | 15 | #include 16 | #include 17 | 18 | #define PATH "PATH=" 19 | 20 | static bool starts_with_PATH(char *full_path) 21 | { 22 | char *path_suffix; 23 | 24 | path_suffix = PATH; 25 | while (*full_path != NULL && *path_suffix != NULL) 26 | { 27 | if (*full_path != *path_suffix) 28 | return (false); 29 | full_path++; 30 | path_suffix++; 31 | } 32 | if (*path_suffix != NULL) 33 | return (false); 34 | return (true); 35 | } 36 | 37 | static char *skip_PATH(char *full_path) 38 | { 39 | char *path_suffix; 40 | char *clean_path; 41 | 42 | path_suffix = PATH; 43 | clean_path = full_path; 44 | while (*clean_path != NULL && *path_suffix != NULL) 45 | { 46 | if (*clean_path != *path_suffix) 47 | return (NULL); 48 | clean_path++; 49 | path_suffix++; 50 | } 51 | return (clean_path); 52 | } 53 | 54 | static char *get_full_path(char **envp) 55 | { 56 | while (*envp) 57 | { 58 | if (starts_with_PATH(*envp)) 59 | return (*envp); 60 | envp++; 61 | } 62 | return (NULL); 63 | } 64 | 65 | static void print_environment_variables(char **environment_variables) 66 | { 67 | int ev_count; 68 | 69 | ev_count = 0; 70 | printf("=== ENVIRONMENT VARIABLES ===\n"); 71 | while (*environment_variables) 72 | { 73 | printf("%s\n", *environment_variables++); 74 | ev_count++; 75 | } 76 | printf("COUNT: %i\n", ev_count); 77 | } 78 | 79 | int main(int argc, char **argv, char **envp) 80 | { 81 | char *paths; 82 | 83 | print_environment_variables(envp); 84 | paths = get_full_path(envp); 85 | paths = skip_PATH(paths); 86 | printf("=== PATHS ===\n"); 87 | printf("%s\n", paths); 88 | } 89 | -------------------------------------------------------------------------------- /snippets/ping_pipe_grep_parent.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ping_pipe_grep_parent.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 23:21:12 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/01 15:05:25 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc ping_pipe_grep_parent.c && ./a.out 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | #define CHILD_PROCESS_ID 0 22 | 23 | static void die(void) 24 | { 25 | perror("\033[0;31mERROR!\033[0m"); 26 | exit(EXIT_FAILURE); 27 | } 28 | 29 | static void handle_child(int pipe_descriptors[2]) 30 | { 31 | // Write the output of ping to STDOUT 32 | dup2(pipe_descriptors[1], STDOUT_FILENO); 33 | // Close file descriptors in child process 34 | close(pipe_descriptors[0]); 35 | close(pipe_descriptors[1]); 36 | // Executes ping 37 | execlp("ping", "ping", "-c", "5", "google.com", NULL); 38 | } 39 | 40 | static void handle_parent(int pipe_descriptors[2], int child_pid) 41 | { 42 | // Write the output of ping to STDOUT 43 | dup2(pipe_descriptors[0], STDIN_FILENO); 44 | // Close file descriptors in child process 45 | close(pipe_descriptors[0]); 46 | close(pipe_descriptors[1]); 47 | // Executes ping 48 | execlp("grep", "grep", "rtt", NULL); 49 | // Wait for child process to finish executing 50 | waitpid(child_pid, NULL, 0); 51 | } 52 | 53 | int main(int argc, char **argv) 54 | { 55 | int pipe_descriptors[2]; 56 | int child_pid; 57 | 58 | // Creates a pipe: 59 | // Bytes written on pipe_descriptors[1] can be read from pipe_descriptors[0] 60 | if (pipe(pipe_descriptors) == -1) 61 | die(); 62 | 63 | // Creates a clone of this process 64 | child_pid = fork(); 65 | if (child_pid < 0) 66 | die(); 67 | 68 | if (child_pid == CHILD_PROCESS_ID) 69 | handle_child(pipe_descriptors); 70 | 71 | if (child_pid != CHILD_PROCESS_ID) 72 | handle_parent(pipe_descriptors, child_pid); 73 | 74 | return (EXIT_SUCCESS); 75 | } 76 | -------------------------------------------------------------------------------- /includes/defines_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* defines_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 18:20:45 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/26 01:20:54 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DEFINES_BONUS_H 14 | # define DEFINES_BONUS_H 15 | 16 | # define CHILD_PROCESS_ID 0 17 | 18 | # define PIPE_READ 0 19 | # define PIPE_WRITE 1 20 | 21 | # define CREATE_PERMISSION 0000664 22 | 23 | # define PATH_PREFIX "PATH=" 24 | # define PATH_PREFIX_LENGTH 5 25 | 26 | # define NOT_ASCII -42 27 | 28 | # define HDOC_IDENTIFIER "here_doc" 29 | # define HDOC_FEED "> " 30 | 31 | /******************************************************************************\ 32 | * MESSAGES 33 | \******************************************************************************/ 34 | 35 | # define HELP_MSG "Welcome to lpaulo-m's pipex!\n\ 36 | \n\ 37 | USAGE:\n\ 38 | ./pipex file1 \"cmd1\" \"cmd2\" \"cmd3\" ... \"cmdn\" file2\n\ 39 | behaves like: < file1 cmd1 | cmd2 | cmd3 | ... | cmdn > file2\n\ 40 | \n\ 41 | ./pipex here_doc LIMITER \"cmd1\" \"cmd2\" file\n\ 42 | behaves like: cmd1 << LIMITER | cmd2 >> file\n\ 43 | \n\ 44 | EXAMPLES:\n\ 45 | ./pipex infile \"ls -l\" \"grep a\" \"wc -l\" outfile\n\ 46 | ./pipex infile \"cat\" \"tr a b\" \"tr b a\" \"tr a b\" \"tr b a\" outfile\n\ 47 | \n\ 48 | ./pipex here_doc l \"grep a\" \"wc -l\" outfile\n\ 49 | ./pipex here_doc x \"cat\" \"tr a b\" outfile\n\ 50 | \n\ 51 | " 52 | 53 | /******************************************************************************\ 54 | * ERRORS 55 | \******************************************************************************/ 56 | 57 | # define EXIT_SUCCESS_STR "0\n" 58 | # define EXIT_FAILURE_STR "1\n" 59 | 60 | # define EKEYEXPIRED 127 61 | # define EKEYEXPIRED_STR "127\n" 62 | 63 | # define ERR_GENERIC_RED "\033[0;31mERROR" 64 | # define ERR_NULL_POINTER "ERROR: critical null pointer" 65 | # define ERR_GNL "ERROR: couldn't read stdin (GNL)" 66 | # define ERR_NO_CMD "command not found" 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /snippets/ping_pipe_grep.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ping_pipe_grep.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 23:21:12 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/28 22:35:47 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc ping_pipe_grep.c && ./a.out 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | #define CHILD_PROCESS_ID 0 22 | 23 | static void die(void) 24 | { 25 | perror("\033[0;31mERROR!\033[0m"); 26 | exit(EXIT_FAILURE); 27 | } 28 | 29 | static void ping_google(int pipe_descriptors[2]) 30 | { 31 | // Write the output of ping to STDOUT 32 | dup2(pipe_descriptors[1], STDOUT_FILENO); 33 | // Close file descriptors in child process 34 | close(pipe_descriptors[0]); 35 | close(pipe_descriptors[1]); 36 | // Executes ping 37 | execlp("ping", "ping", "-c", "5", "google.com", NULL); 38 | } 39 | 40 | static void grep_rtt(int pipe_descriptors[2]) 41 | { 42 | // Write the output of ping to STDOUT 43 | dup2(pipe_descriptors[0], STDIN_FILENO); 44 | // Close file descriptors in child process 45 | close(pipe_descriptors[0]); 46 | close(pipe_descriptors[1]); 47 | // Executes ping 48 | execlp("grep", "grep", "rtt", NULL); 49 | } 50 | 51 | int main(int argc, char **argv) 52 | { 53 | int pipe_descriptors[2]; 54 | int ping_pid; 55 | int grep_pid; 56 | 57 | // Creates a pipe: 58 | // Bytes written on pipe_descriptors[1] can be read from pipe_descriptors[0] 59 | if (pipe(pipe_descriptors) == -1) 60 | die(); 61 | 62 | // Creates a clone of this process 63 | ping_pid = fork(); 64 | if (ping_pid < 0) 65 | die(); 66 | 67 | if (ping_pid == CHILD_PROCESS_ID) 68 | ping_google(pipe_descriptors); 69 | 70 | grep_pid = fork(); 71 | if (grep_pid < 0) 72 | die(); 73 | 74 | if (grep_pid == CHILD_PROCESS_ID) 75 | grep_rtt(pipe_descriptors); 76 | 77 | // Close file descriptors in parent process 78 | close(pipe_descriptors[0]); 79 | close(pipe_descriptors[1]); 80 | 81 | // Wait for child processes to finish executing 82 | waitpid(ping_pid, NULL, 0); 83 | waitpid(grep_pid, NULL, 0); 84 | 85 | return (EXIT_SUCCESS); 86 | } 87 | -------------------------------------------------------------------------------- /scripts/compare.sh: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # compare.sh :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: lpaulo-m +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/03/12 18:00:58 by lpaulo-m #+# #+# # 9 | # Updated: 2022/03/26 01:23:44 by lpaulo-m ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | # Black, Red, Green, Yellow, Blue, Purple, Cyan, White 14 | BK="\033[0;30m" 15 | R="\033[0;31m" 16 | G="\033[0;32m" 17 | Y="\033[0;33m" 18 | B="\033[0;34m" 19 | P="\033[0;35m" 20 | C="\033[0;36m" 21 | W="\033[0;37m" 22 | # Bold 23 | BKB="\033[1;30m" 24 | RB="\033[1;31m" 25 | GB="\033[1;32m" 26 | YB="\033[1;33m" 27 | BB="\033[1;34m" 28 | PB="\033[1;35m" 29 | CB="\033[1;36m" 30 | WB="\033[1;37m" 31 | # Reset Color 32 | RC="\033[0m" 33 | 34 | print_exit_code() { 35 | printf "${C}Exit Code: " 36 | echo $1 37 | printf "${RC}" 38 | } 39 | 40 | print_outfile() { 41 | printf "${Y}Outfile:" 42 | echo 43 | echo "\"\"\"" 44 | cat $1 45 | printf "\"\"\"${RC}" 46 | echo 47 | } 48 | 49 | run_pipex() { 50 | rm $4 51 | printf "${P}========================= PIPEX =======================${RC}\n" 52 | printf "${G}Command: ./pipex $1 \"$2\" \"$3\" $4${RC}" 53 | echo 54 | 55 | printf "${B}Output:" 56 | echo 57 | ./pipex "$1" "$2" "$3" "$4" 58 | exit_code=$? 59 | printf "${RC}" 60 | echo 61 | 62 | print_exit_code "$exit_code" 63 | print_outfile "$4" 64 | } 65 | 66 | run_shell() { 67 | rm $4 68 | printf "${P}========================= SHELL =======================${RC}\n" 69 | printf "${G}Command: < $1 $2 | $3 > $4${RC}" 70 | echo 71 | 72 | printf "${B}Output:" 73 | echo 74 | eval "< $1 $2 | $3 > $4" 75 | exit_code=$? 76 | printf "${RC}" 77 | echo 78 | 79 | print_exit_code "$exit_code" 80 | print_outfile "$4" 81 | } 82 | 83 | print_terminator() { 84 | printf "${P}=======================================================${RC}\n" 85 | echo 86 | echo 87 | } 88 | 89 | compare() { 90 | run_pipex "$1" "$2" "$3" "$4" 91 | run_shell "$1" "$2" "$3" "$4" 92 | 93 | print_terminator 94 | } 95 | 96 | make --silent re || exit 97 | 98 | # compare infile "grep a" "wc -w" outfile 99 | 100 | # compare infile "ls" "wc" outfile 101 | # compare infile "ls -la" "grep *.c" outfile 102 | # compare infile "ls -la" "bad *.c" outfile 103 | # compare infile "ls -l" "wc -l" outfile 104 | # compare infile "ls -l -a -s" "wc -l" outfile 105 | # compare infile "ls -l -a -s" "wc -m" outfile 106 | 107 | # compare infile "cat" "wc" outfile 108 | # compare infile "cat -E" "wc -l" outfile 109 | # compare infile "cat -E" "wc -m" outfile 110 | 111 | # compare .gitignore "tr a b" "tr b c" outfile 112 | # compare EOF "tr a b" "tr b c" outfile 113 | # compare .gitignore "tr x ' '" "tr i ' '" outfile 114 | 115 | # compare .gitignore "tr ex ' X'" "tr pi 'P '" outfile 116 | # compare "infile" "tr a ' '" "tr ' ' x" "outfile" 117 | 118 | compare infile "grep pipex" "wc -lw" outfile 119 | compare infile "cat" "trzero a b" outfile 120 | compare infile "notexisting" "wc" outfile 121 | compare infile "catzado" "wc -w" outfile 122 | 123 | compare bad "cat" "grep x" outfile 124 | compare bad "grep x" "cat" outfile 125 | 126 | # compare /dev/urandom "cat" "head -1" outfile 127 | # compare .gitignore "ping 8.8.8.8" "grep ms" outfile 128 | -------------------------------------------------------------------------------- /snippets/|_parent.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* |_parent.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 23:21:12 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/03/01 15:12:02 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc "|_parent.c" && ./a.out "ls" "wc" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define CHILD_PROCESS_ID 0 21 | 22 | static void die(void) 23 | { 24 | perror("\033[0;31mERROR!\033[0m"); 25 | exit(EXIT_FAILURE); 26 | } 27 | 28 | /* 29 | ** Closes pipe file descritors so processes don't hang. 30 | */ 31 | static void close_pipes_fds(int pipe_fds[2]) 32 | { 33 | close(pipe_fds[0]); 34 | close(pipe_fds[1]); 35 | } 36 | 37 | /* 38 | ** Wait for child processes to finish executing. 39 | */ 40 | static void wait_for_child(int left_pid) 41 | { 42 | waitpid(left_pid, NULL, 0); 43 | } 44 | 45 | /* 46 | ** Creates a pipe... or dies trying ☠️. 47 | ** Bytes written on pipe_fds[1] can be read from pipe_fds[0]. 48 | */ 49 | static int pipe_or_die(int pipe_fds[2]) 50 | { 51 | int pipe_return; 52 | 53 | pipe_return = pipe(pipe_fds); 54 | if (pipe_return < 0) 55 | die(); 56 | } 57 | 58 | /* 59 | ** Creates a child process... or dies trying ☠️. 60 | ** The child process is almost identical to its parent, 61 | ** with a copy of its memory space at the time of fork. 62 | */ 63 | static int fork_or_die(void) 64 | { 65 | int pid; 66 | 67 | pid = fork(); 68 | if (pid < 0) 69 | die(); 70 | return (pid); 71 | } 72 | 73 | /* 74 | ** Redirects the STDOUT of the current process to the pipe's input. 75 | */ 76 | static void stdout_to_pipe(int pipe_fds[2]) 77 | { 78 | dup2(pipe_fds[1], STDOUT_FILENO); 79 | } 80 | 81 | /* 82 | ** Redirects the pipe's output to the STDIN of the current process. 83 | */ 84 | static void pipe_to_stdin(int pipe_fds[2]) 85 | { 86 | dup2(pipe_fds[0], STDIN_FILENO); 87 | } 88 | 89 | /* 90 | ** Executes a file in PATH without any arguments. 91 | */ 92 | static void execute_no_args(char *command) 93 | { 94 | execlp(command, command, NULL); 95 | } 96 | 97 | static void handle_child(int pipe_fds[2], char *left_command) 98 | { 99 | stdout_to_pipe(pipe_fds); 100 | close_pipes_fds(pipe_fds); 101 | execute_no_args(left_command); 102 | } 103 | 104 | static void handle_parent(int pipe_fds[2], char *right_command, int left_pid) 105 | { 106 | pipe_to_stdin(pipe_fds); 107 | close_pipes_fds(pipe_fds); 108 | execute_no_args(right_command); 109 | wait_for_child(left_pid); 110 | } 111 | 112 | static void handle_arguments( 113 | int argc, 114 | char **argv, 115 | char **left_command, 116 | char **right_command) 117 | { 118 | if (argc != 3) 119 | die(); 120 | *left_command = argv[1]; 121 | *right_command = argv[2]; 122 | printf("excuting \"%s | %s\"\n", *left_command, *right_command); 123 | } 124 | 125 | int main(int argc, char **argv, char **envp) 126 | { 127 | int pipe_fds[2]; 128 | char *left_command; 129 | int left_pid; 130 | char *right_command; 131 | 132 | handle_arguments(argc, argv, &left_command, &right_command); 133 | pipe_or_die(pipe_fds); 134 | 135 | left_pid = fork_or_die(); 136 | if (left_pid == CHILD_PROCESS_ID) 137 | handle_child(pipe_fds, left_command); 138 | 139 | if (left_pid != CHILD_PROCESS_ID) 140 | handle_parent(pipe_fds, right_command, left_pid); 141 | 142 | return (EXIT_SUCCESS); 143 | } 144 | -------------------------------------------------------------------------------- /snippets/|.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* |.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 23:21:12 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/28 22:35:47 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc "|.c" && ./a.out "ls" "wc" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define CHILD_PROCESS_ID 0 21 | 22 | static void die(void) 23 | { 24 | perror("\033[0;31mERROR!\033[0m"); 25 | exit(EXIT_FAILURE); 26 | } 27 | 28 | /* 29 | ** Closes pipe file descritors so processes don't hang. 30 | */ 31 | static void close_pipes_fds(int pipe_fds[2]) 32 | { 33 | close(pipe_fds[0]); 34 | close(pipe_fds[1]); 35 | } 36 | 37 | /* 38 | ** Wait for child processes to finish executing. 39 | */ 40 | static void wait_for_children(int left_pid, int right_pid) 41 | { 42 | waitpid(left_pid, NULL, 0); 43 | waitpid(right_pid, NULL, 0); 44 | } 45 | 46 | /* 47 | ** Creates a pipe... or dies trying ☠️. 48 | ** Bytes written on pipe_fds[1] can be read from pipe_fds[0]. 49 | */ 50 | static int pipe_or_die(int pipe_fds[2]) 51 | { 52 | int pipe_return; 53 | 54 | pipe_return = pipe(pipe_fds); 55 | if (pipe_return < 0) 56 | die(); 57 | } 58 | 59 | /* 60 | ** Creates a child process... or dies trying ☠️. 61 | ** The child process is almost identical to its parent, 62 | ** with a copy of its memory space at the time of fork. 63 | */ 64 | static int fork_or_die(void) 65 | { 66 | int pid; 67 | 68 | pid = fork(); 69 | if (pid < 0) 70 | die(); 71 | return (pid); 72 | } 73 | 74 | /* 75 | ** Redirects the STDOUT of the current process to the pipe's input. 76 | */ 77 | static void stdout_to_pipe(int pipe_fds[2]) 78 | { 79 | dup2(pipe_fds[1], STDOUT_FILENO); 80 | } 81 | 82 | /* 83 | ** Redirects the pipe's output to the STDIN of the current process. 84 | */ 85 | static void pipe_to_stdin(int pipe_fds[2]) 86 | { 87 | dup2(pipe_fds[0], STDIN_FILENO); 88 | } 89 | 90 | /* 91 | ** Executes a file in PATH without any arguments. 92 | */ 93 | static void execute_no_args(char *command) 94 | { 95 | execlp(command, command, NULL); 96 | } 97 | 98 | static void run_left(int pipe_fds[2], char *left_command) 99 | { 100 | stdout_to_pipe(pipe_fds); 101 | close_pipes_fds(pipe_fds); 102 | execute_no_args(left_command); 103 | } 104 | 105 | static void run_right(int pipe_fds[2], char *right_command) 106 | { 107 | pipe_to_stdin(pipe_fds); 108 | close_pipes_fds(pipe_fds); 109 | execute_no_args(right_command); 110 | } 111 | 112 | static void handle_arguments( 113 | int argc, 114 | char **argv, 115 | char **left_command, 116 | char **right_command) 117 | { 118 | if (argc != 3) 119 | die(); 120 | *left_command = argv[1]; 121 | *right_command = argv[2]; 122 | printf("excuting \"%s | %s\"\n", *left_command, *right_command); 123 | } 124 | 125 | int main(int argc, char **argv, char **envp) 126 | { 127 | int pipe_fds[2]; 128 | char *left_command; 129 | int left_pid; 130 | char *right_command; 131 | int right_pid; 132 | 133 | handle_arguments(argc, argv, &left_command, &right_command); 134 | pipe_or_die(pipe_fds); 135 | 136 | left_pid = fork_or_die(); 137 | if (left_pid == CHILD_PROCESS_ID) 138 | run_left(pipe_fds, left_command); 139 | 140 | right_pid = fork_or_die(); 141 | if (right_pid == CHILD_PROCESS_ID) 142 | run_right(pipe_fds, right_command); 143 | 144 | close_pipes_fds(pipe_fds); 145 | wait_for_children(left_pid, right_pid); 146 | 147 | return (EXIT_SUCCESS); 148 | } 149 | -------------------------------------------------------------------------------- /examples/|_execve.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* |_execve.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 23:21:12 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/28 22:35:47 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | // gcc "|_execve.c" && ./a.out "ls" "wc" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define CHILD_PROCESS_ID 0 21 | 22 | char **g_env_vars; 23 | 24 | static void die(void) 25 | { 26 | perror("\033[0;31mERROR!\033[0m"); 27 | exit(EXIT_FAILURE); 28 | } 29 | 30 | /* 31 | ** Closes pipe file descritors so processes don't hang. 32 | */ 33 | static void close_pipes_fds(int pipe_fds[2]) 34 | { 35 | close(pipe_fds[0]); 36 | close(pipe_fds[1]); 37 | } 38 | 39 | /* 40 | ** Wait for child processes to finish executing. 41 | */ 42 | static void wait_for_children(int left_pid, int right_pid) 43 | { 44 | waitpid(left_pid, NULL, 0); 45 | waitpid(right_pid, NULL, 0); 46 | } 47 | 48 | /* 49 | ** Creates a pipe... or dies trying ☠️. 50 | ** Bytes written on pipe_fds[1] can be read from pipe_fds[0]. 51 | */ 52 | static int pipe_or_die(int pipe_fds[2]) 53 | { 54 | int pipe_return; 55 | 56 | pipe_return = pipe(pipe_fds); 57 | if (pipe_return < 0) 58 | die(); 59 | } 60 | 61 | /* 62 | ** Creates a child process... or dies trying ☠️. 63 | ** The child process is almost identical to its parent, 64 | ** with a copy of its memory space at the time of fork. 65 | */ 66 | static int fork_or_die(void) 67 | { 68 | int pid; 69 | 70 | pid = fork(); 71 | if (pid < 0) 72 | die(); 73 | return (pid); 74 | } 75 | 76 | /* 77 | ** Redirects the STDOUT of the current process to the pipe's input. 78 | */ 79 | static void stdout_to_pipe(int pipe_fds[2]) 80 | { 81 | dup2(pipe_fds[1], STDOUT_FILENO); 82 | } 83 | 84 | /* 85 | ** Redirects the pipe's output to the STDIN of the current process. 86 | */ 87 | static void pipe_to_stdin(int pipe_fds[2]) 88 | { 89 | dup2(pipe_fds[0], STDIN_FILENO); 90 | } 91 | 92 | /* 93 | ** Executes a file in PATH without any arguments. 94 | */ 95 | static void execute_or_die(char *command) 96 | { 97 | int execve_return; 98 | 99 | 100 | execve_return = execve(command, command, g_env_vars); 101 | if (execve_return < 0) 102 | die(); 103 | } 104 | 105 | static void run_left(int pipe_fds[2], char *left_command) 106 | { 107 | stdout_to_pipe(pipe_fds); 108 | close_pipes_fds(pipe_fds); 109 | execute_or_die(left_command); 110 | } 111 | 112 | static void run_right(int pipe_fds[2], char *right_command) 113 | { 114 | pipe_to_stdin(pipe_fds); 115 | close_pipes_fds(pipe_fds); 116 | execute_or_die(right_command); 117 | } 118 | 119 | static void handle_arguments( 120 | int argc, 121 | char **argv, 122 | char **left_command, 123 | char **right_command) 124 | { 125 | if (argc != 3) 126 | die(); 127 | *left_command = argv[1]; 128 | *right_command = argv[2]; 129 | printf("excuting \"%s | %s\"\n", *left_command, *right_command); 130 | 131 | } 132 | 133 | // TODO: HANDLE COMMAND ARGUMENTS WITH ft_split. 134 | int main(int argc, char **argv, char **envp) 135 | { 136 | int pipe_fds[2]; 137 | char *left_command; 138 | int left_pid; 139 | char *right_command; 140 | int right_pid; 141 | 142 | handle_arguments(argc, argv, &left_command, &right_command); 143 | g_env_vars = envp; 144 | pipe_or_die(pipe_fds); 145 | 146 | left_pid = fork_or_die(); 147 | if (left_pid == CHILD_PROCESS_ID) 148 | run_left(pipe_fds, left_command); 149 | 150 | right_pid = fork_or_die(); 151 | if (right_pid == CHILD_PROCESS_ID) 152 | run_right(pipe_fds, right_command); 153 | 154 | close_pipes_fds(pipe_fds); 155 | wait_for_children(left_pid, right_pid); 156 | 157 | return (EXIT_SUCCESS); 158 | } 159 | -------------------------------------------------------------------------------- /includes/pipex_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* pipex.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: lpaulo-m +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/25 10:30:54 by lpaulo-m #+# #+# */ 9 | /* Updated: 2022/02/25 10:32:28 by lpaulo-m ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PIPEX_BONUS_H 14 | # define PIPEX_BONUS_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | 22 | typedef struct s_file 23 | { 24 | char *path; 25 | int fd; 26 | } t_file; 27 | 28 | typedef struct s_exec 29 | { 30 | char *raw; 31 | char **tokens; 32 | char *cmd; 33 | char *path; 34 | 35 | int code; 36 | } t_exec; 37 | 38 | typedef struct s_pipex 39 | { 40 | int argc; 41 | int arg; 42 | char **argv; 43 | 44 | char **envp; 45 | char *path; 46 | char **paths; 47 | 48 | char *limiter; 49 | char *last_cmd; 50 | 51 | t_file infile; 52 | t_file outfile; 53 | 54 | t_list *free_me; 55 | } t_pipex; 56 | 57 | int nex(int argc, char **argv, char **envp); 58 | int hdoc(int argc, char **argv, char **envp); 59 | 60 | /******************************************************************************\ 61 | * INITIALIZERS 62 | \******************************************************************************/ 63 | 64 | void initialize_control(t_pipex *ctl, int argc, char **argv, char **envp); 65 | void initialize_hdoc(t_pipex *ctl); 66 | void initialize_nex(t_pipex *ctl); 67 | 68 | void initialize_environment(t_pipex *ctl); 69 | 70 | /******************************************************************************\ 71 | * CHILDREN 72 | \******************************************************************************/ 73 | 74 | pid_t fork_or_die(void); 75 | 76 | void get_hdoc(t_pipex *ctl); 77 | void handle_child(t_pipex *ctl, char *raw_cmd); 78 | 79 | /******************************************************************************\ 80 | * COMMANDS 81 | \******************************************************************************/ 82 | 83 | void command_or_die(t_pipex *ctl, char *raw_cmd); 84 | 85 | char *get_clean_path_or_die(char **envp); 86 | char **get_paths_or_die(char **envp); 87 | 88 | char *find_executable(char *command, char **paths); 89 | char *find_executable_or_die(char *command, char **paths); 90 | 91 | char **split_command_or_die(char *raw_command); 92 | char **tokenize_or_die(char *raw_command); 93 | 94 | void execute_or_die(t_pipex *ctl, char *raw_cmd); 95 | 96 | /******************************************************************************\ 97 | * FILES 98 | \******************************************************************************/ 99 | 100 | int create_file_or_die(char *path); 101 | int open_file_or_die(char *path); 102 | int close_or_die(int close_me); 103 | 104 | int open_infile_or_die(t_pipex *ctl); 105 | int create_outfile_or_die(t_pipex *ctl); 106 | int open_outfile_or_die(t_pipex *ctl); 107 | 108 | /******************************************************************************\ 109 | * PIPES 110 | \******************************************************************************/ 111 | 112 | void pipe_or_die(int pipe_fds[2]); 113 | void close_pipe(int pipe_fds[2]); 114 | 115 | void stdin_to_pipe(int pipe_fds[2]); 116 | void pipe_to_stdin(int pipe_fds[2]); 117 | 118 | void stdout_to_pipe(int pipe_fds[2]); 119 | void pipe_to_stdout(int pipe_fds[2]); 120 | 121 | void file_to_stdin(int infile_fd); 122 | void stdout_to_file(int outfile_fd); 123 | 124 | void str_to_pipe(int pipe_fds[2], char *str); 125 | 126 | /******************************************************************************\ 127 | * CLEANUP 128 | \******************************************************************************/ 129 | 130 | void free_memory(t_pipex *ctl); 131 | 132 | /******************************************************************************\ 133 | * ERRORS 134 | \******************************************************************************/ 135 | 136 | void check_argc(int argc); 137 | 138 | void die_if_null(void *ptr); 139 | void die(void); 140 | void die2(char *location); 141 | void die3(char *location, int exit_status); 142 | void die4(int exit_status); 143 | void die5(char *location, char *message, int exit_status); 144 | void die6(t_pipex *ctl, char *location); 145 | void die_cmd(t_pipex *ctl, char *raw_cmd); 146 | 147 | void print_error(char *location, char *message); 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /snippets/error_numbers: -------------------------------------------------------------------------------- 1 | EPERM 1 Operation not permitted 2 | ENOENT 2 No such file or directory 3 | ESRCH 3 No such process 4 | EINTR 4 Interrupted system call 5 | EIO 5 Input/output error 6 | ENXIO 6 No such device or address 7 | E2BIG 7 Argument list too long 8 | ENOEXEC 8 Exec format error 9 | EBADF 9 Bad file descriptor 10 | ECHILD 10 No child processes 11 | EAGAIN 11 Resource temporarily unavailable 12 | ENOMEM 12 Cannot allocate memory 13 | EACCES 13 Permission denied 14 | EFAULT 14 Bad address 15 | ENOTBLK 15 Block device required 16 | EBUSY 16 Device or resource busy 17 | EEXIST 17 File exists 18 | EXDEV 18 Invalid cross-device link 19 | ENODEV 19 No such device 20 | ENOTDIR 20 Not a directory 21 | EISDIR 21 Is a directory 22 | EINVAL 22 Invalid argument 23 | ENFILE 23 Too many open files in system 24 | EMFILE 24 Too many open files 25 | ENOTTY 25 Inappropriate ioctl for device 26 | ETXTBSY 26 Text file busy 27 | EFBIG 27 File too large 28 | ENOSPC 28 No space left on device 29 | ESPIPE 29 Illegal seek 30 | EROFS 30 Read-only file system 31 | EMLINK 31 Too many links 32 | EPIPE 32 Broken pipe 33 | EDOM 33 Numerical argument out of domain 34 | ERANGE 34 Numerical result out of range 35 | EDEADLK 35 Resource deadlock avoided 36 | ENAMETOOLONG 36 File name too long 37 | ENOLCK 37 No locks available 38 | ENOSYS 38 Function not implemented 39 | ENOTEMPTY 39 Directory not empty 40 | ELOOP 40 Too many levels of symbolic links 41 | EWOULDBLOCK 11 Resource temporarily unavailable 42 | ENOMSG 42 No message of desired type 43 | EIDRM 43 Identifier removed 44 | ECHRNG 44 Channel number out of range 45 | EL2NSYNC 45 Level 2 not synchronized 46 | EL3HLT 46 Level 3 halted 47 | EL3RST 47 Level 3 reset 48 | ELNRNG 48 Link number out of range 49 | EUNATCH 49 Protocol driver not attached 50 | ENOCSI 50 No CSI structure available 51 | EL2HLT 51 Level 2 halted 52 | EBADE 52 Invalid exchange 53 | EBADR 53 Invalid request descriptor 54 | EXFULL 54 Exchange full 55 | ENOANO 55 No anode 56 | EBADRQC 56 Invalid request code 57 | EBADSLT 57 Invalid slot 58 | EDEADLOCK 35 Resource deadlock avoided 59 | EBFONT 59 Bad font file format 60 | ENOSTR 60 Device not a stream 61 | ENODATA 61 No data available 62 | ETIME 62 Timer expired 63 | ENOSR 63 Out of streams resources 64 | ENONET 64 Machine is not on the network 65 | ENOPKG 65 Package not installed 66 | EREMOTE 66 Object is remote 67 | ENOLINK 67 Link has been severed 68 | EADV 68 Advertise error 69 | ESRMNT 69 Srmount error 70 | ECOMM 70 Communication error on send 71 | EPROTO 71 Protocol error 72 | EMULTIHOP 72 Multihop attempted 73 | EDOTDOT 73 RFS specific error 74 | EBADMSG 74 Bad message 75 | EOVERFLOW 75 Value too large for defined data type 76 | ENOTUNIQ 76 Name not unique on network 77 | EBADFD 77 File descriptor in bad state 78 | EREMCHG 78 Remote address changed 79 | ELIBACC 79 Can not access a needed shared library 80 | ELIBBAD 80 Accessing a corrupted shared library 81 | ELIBSCN 81 .lib section in a.out corrupted 82 | ELIBMAX 82 Attempting to link in too many shared libraries 83 | ELIBEXEC 83 Cannot exec a shared library directly 84 | EILSEQ 84 Invalid or incomplete multibyte or wide character 85 | ERESTART 85 Interrupted system call should be restarted 86 | ESTRPIPE 86 Streams pipe error 87 | EUSERS 87 Too many users 88 | ENOTSOCK 88 Socket operation on non-socket 89 | EDESTADDRREQ 89 Destination address required 90 | EMSGSIZE 90 Message too long 91 | EPROTOTYPE 91 Protocol wrong type for socket 92 | ENOPROTOOPT 92 Protocol not available 93 | EPROTONOSUPPORT 93 Protocol not supported 94 | ESOCKTNOSUPPORT 94 Socket type not supported 95 | EOPNOTSUPP 95 Operation not supported 96 | EPFNOSUPPORT 96 Protocol family not supported 97 | EAFNOSUPPORT 97 Address family not supported by protocol 98 | EADDRINUSE 98 Address already in use 99 | EADDRNOTAVAIL 99 Cannot assign requested address 100 | ENETDOWN 100 Network is down 101 | ENETUNREACH 101 Network is unreachable 102 | ENETRESET 102 Network dropped connection on reset 103 | ECONNABORTED 103 Software caused connection abort 104 | ECONNRESET 104 Connection reset by peer 105 | ENOBUFS 105 No buffer space available 106 | EISCONN 106 Transport endpoint is already connected 107 | ENOTCONN 107 Transport endpoint is not connected 108 | ESHUTDOWN 108 Cannot send after transport endpoint shutdown 109 | ETOOMANYREFS 109 Too many references: cannot splice 110 | ETIMEDOUT 110 Connection timed out 111 | ECONNREFUSED 111 Connection refused 112 | EHOSTDOWN 112 Host is down 113 | EHOSTUNREACH 113 No route to host 114 | EALREADY 114 Operation already in progress 115 | EINPROGRESS 115 Operation now in progress 116 | ESTALE 116 Stale file handle 117 | EUCLEAN 117 Structure needs cleaning 118 | ENOTNAM 118 Not a XENIX named type file 119 | ENAVAIL 119 No XENIX semaphores available 120 | EISNAM 120 Is a named type file 121 | EREMOTEIO 121 Remote I/O error 122 | EDQUOT 122 Disk quota exceeded 123 | ENOMEDIUM 123 No medium found 124 | EMEDIUMTYPE 124 Wrong medium type 125 | ECANCELED 125 Operation canceled 126 | ENOKEY 126 Required key not available 127 | EKEYEXPIRED 127 Key has expired 128 | EKEYREVOKED 128 Key has been revoked 129 | EKEYREJECTED 129 Key was rejected by service 130 | EOWNERDEAD 130 Owner died 131 | ENOTRECOVERABLE 131 State not recoverable 132 | ERFKILL 132 Operation not possible due to RF-kill 133 | EHWPOISON 133 Memory page has hardware error 134 | ENOTSUP 95 Operation not supported 135 | --------------------------------------------------------------------------------