add envp pointer from main code
This commit is contained in:
		
							parent
							
								
									4b438e7f7a
								
							
						
					
					
						commit
						0480a7a73f
					
				| @ -196,7 +196,14 @@ Tue Oct 17 08:55:01 CEST 2023 | ||||
| tth@redlady:~$ | ||||
| \end{verbatim} | ||||
| 
 | ||||
| Simple et efficace. | ||||
| Simple et efficace. \textbf{Mais\dots} | ||||
| 
 | ||||
| Mais ça ne marche pas à tous les coups comme vous le montre | ||||
| clairement cet exemple. L'utilisation de la fonction | ||||
| \texttt{getenv(3)} est très facilement contournable. | ||||
| 
 | ||||
| \lstinputlisting[language=C]{code/C/use_envp.c} | ||||
| 
 | ||||
| 
 | ||||
| % ============================================================== | ||||
| 
 | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
| # exemples pour le chapitre sur le C
 | ||||
| # new Sat Feb 11 12:06:34 CET 2023
 | ||||
| 
 | ||||
| all:	no-op slowprint fgets-simple packtest | ||||
| all:	no-op slowprint fgets-simple packtest use_envp | ||||
| 
 | ||||
| no-op:			no-op.c Makefile | ||||
| 	gcc -Wall $< -o $@ | ||||
| @ -19,3 +19,8 @@ demo-strtok:		demo-strtok.c Makefile | ||||
| # added Wed Mar 27 10:01:41 UTC 2024
 | ||||
| packtest:		packtest.c | ||||
| 	gcc -Wall $< -o $@ | ||||
| 
 | ||||
| # added Thu Aug  8 13:44:58 UTC 2024
 | ||||
| use_envp:	use_envp.c Makefile | ||||
| 	gcc -Wall $< -o $@ | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										16
									
								
								code/C/use_envp.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								code/C/use_envp.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| /*		using envp for fun and profit		*/ | ||||
| 
 | ||||
| #include  <stdio.h> | ||||
| 
 | ||||
| int main(int argc, char *argv[], char *envp[]) | ||||
| { | ||||
| char	*cptr; | ||||
| int	idx = 0; | ||||
| cptr = envp[idx]; | ||||
| while ( NULL != (cptr=envp[idx]) ) { | ||||
| 	fprintf(stderr, "envp[%d] %p --> %s\n", | ||||
| 					idx, cptr, cptr); | ||||
| 	idx++; | ||||
| 	}	 | ||||
| return 0; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 tTh
						tTh