mirror of
https://gitlab.com/blau_araujo/cblc.git
synced 2025-05-09 18:16:37 -03:00
exemplos de acesso ao ambiente
This commit is contained in:
parent
183af0896e
commit
b7b146aefa
1 changed files with 23 additions and 12 deletions
|
@ -1,22 +1,33 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
extern char **environ;
|
||||||
|
|
||||||
|
void print_list(char *list[]);
|
||||||
|
|
||||||
|
int main(int argc, char **argv, char **envp) {
|
||||||
|
|
||||||
|
// Listando ponteiro 'environ'...
|
||||||
|
print_list(environ);
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
|
// Função getenv...
|
||||||
|
char *env = getenv("SHELL");
|
||||||
|
printf("env = %s\n", env);
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
|
// Listando parâmetro 'envp'...
|
||||||
|
print_list(envp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void print_list(char *list[]) {
|
void print_list(char *list[]) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (list[i] != NULL) {
|
while (list[i] != NULL) {
|
||||||
printf("[%d] => %s\n", i, list[i]);
|
printf("[%d] => %p => %s\n", i, list[i], list[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp) {
|
|
||||||
|
|
||||||
// O vetor de ambiente (envp) é um vetor de strings
|
|
||||||
// terminado com um ponteiro nulo (NULL)...
|
|
||||||
|
|
||||||
print_list(envp);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue