| 83 | ****************************************************************************/ |
| 84 | |
| 85 | ENVPATH_HANDLE envpath_init(FAR const char *name) |
| 86 | { |
| 87 | FAR struct envpath_s *envpath; |
| 88 | FAR char *path; |
| 89 | size_t size; |
| 90 | |
| 91 | /* Get the value of the PATH variable */ |
| 92 | |
| 93 | path = getenv(name); |
| 94 | if (!path) |
| 95 | { |
| 96 | /* getenv() will return a NULL value if the PATH variable does not |
| 97 | * exist in the environment. |
| 98 | */ |
| 99 | |
| 100 | return NULL; |
| 101 | } |
| 102 | |
| 103 | /* Allocate a container for the PATH variable contents */ |
| 104 | |
| 105 | size = strlen(path) + 1; |
| 106 | envpath = (FAR struct envpath_s *) |
| 107 | lib_malloc(SIZEOF_ENVPATH_S(size)); |
| 108 | |
| 109 | if (!envpath) |
| 110 | { |
| 111 | /* Ooops.. we are out of memory */ |
| 112 | |
| 113 | return NULL; |
| 114 | } |
| 115 | |
| 116 | /* Populate the container */ |
| 117 | |
| 118 | strlcpy(envpath->path, path, size); |
| 119 | envpath->next = envpath->path; |
| 120 | |
| 121 | /* And return the containing cast to an opaque handle */ |
| 122 | |
| 123 | return envpath; |
| 124 | } |
| 125 | |
| 126 | /**************************************************************************** |
| 127 | * Name: envpath_next |
no test coverage detected