tiny-shell 0.2
A mini shell project aiming to gain knowledge about Win32 and Linux API
Loading...
Searching...
No Matches
env.c
Go to the documentation of this file.
1#include "env.h"
2#include "../core/config.h"
3#include "../core/io_wrap.h"
4#include "../os/operations.h"
5#include <stdlib.h>
6
7enum run_result run_set_env(const os_char *name, const os_char *val) {
8 return set_shell_env(name, val) ? RUN_OK : RUN_FAILED;
9}
10
11enum run_result run_unset_env(const os_char *name) {
12 return unset_shell_env(name) ? RUN_OK : RUN_FAILED;
13}
14
16 os_char *env = get_all_shell_env_display();
17 if(!env) {
18 return RUN_FAILED;
19 } else {
20 format_output("%s\n", env);
21 free(env);
22 return RUN_OK;
23 }
24}
25
26enum run_result run_get_env(const os_char *name) {
27 os_char buffer[ENV_VAR_BUFFER_SIZE];
28 if(!get_shell_env(name, ENV_VAR_BUFFER_SIZE, buffer)) {
29 return RUN_FAILED;
30 }
31 format_output("%s\n", buffer);
32 return RUN_OK;
33}
#define ENV_VAR_BUFFER_SIZE
Definition config.h:8
enum run_result run_unset_env(const os_char *name)
Unset current process's environment variable.
Definition env.c:11
enum run_result run_get_all_env()
Set current process's environment variable.
Definition env.c:15
enum run_result run_get_env(const os_char *name)
Set current process's environment variable.
Definition env.c:26
enum run_result run_set_env(const os_char *name, const os_char *val)
Set current process's environment variable.
Definition env.c:7
void format_output(char *fmt,...)
Used format_xxx instead of printf and such for uniform output.
Definition io_wrap.c:80
bool get_shell_env(const os_char *var, unsigned int buffer_size, os_char *buffer)
Get value of an an environment variable.
os_char * get_all_shell_env_display()
Get all current environment variable.
bool set_shell_env(const os_char *name, const os_char *val)
Set environment variable of the shell process.
bool unset_shell_env(const os_char *name)
Unset environment variable of the shell process.
run_result
Result of the execution of a command line.
Definition res.h:6
@ RUN_OK
Definition res.h:7
@ RUN_FAILED
Definition res.h:9