39
39
#include "supervisor/filesystem.h"
40
40
#include "supervisor/memory.h"
41
41
42
- #define ENVIRON_PATH "settings.toml"
42
+ #define GETENV_PATH "settings.toml"
43
43
44
44
#if defined(UNIX )
45
45
typedef FILE * file_arg ;
@@ -178,7 +178,7 @@ STATIC bool key_matches(file_arg *active_file, const char *key) {
178
178
return true;
179
179
}
180
180
181
- STATIC os_environ_err_t read_unicode_escape (file_arg * active_file , int sz , vstr_t * buf ) {
181
+ STATIC os_getenv_err_t read_unicode_escape (file_arg * active_file , int sz , vstr_t * buf ) {
182
182
char hex_buf [sz + 1 ];
183
183
for (int i = 0 ; i < sz ; i ++ ) {
184
184
hex_buf [i ] = get_next_byte (active_file );
@@ -197,7 +197,7 @@ STATIC os_environ_err_t read_unicode_escape(file_arg *active_file, int sz, vstr_
197
197
}
198
198
199
199
// Read a quoted string
200
- STATIC os_environ_err_t read_string_value (file_arg * active_file , vstr_t * buf ) {
200
+ STATIC os_getenv_err_t read_string_value (file_arg * active_file , vstr_t * buf ) {
201
201
while (true) {
202
202
int character = get_next_byte (active_file );
203
203
switch (character ) {
@@ -244,7 +244,7 @@ STATIC os_environ_err_t read_string_value(file_arg *active_file, vstr_t *buf) {
244
244
case 'U' :
245
245
case 'u' : {
246
246
int sz = (character == 'u' ) ? 4 : 8 ;
247
- os_environ_err_t res ;
247
+ os_getenv_err_t res ;
248
248
res = read_unicode_escape (active_file , sz , buf );
249
249
if (res != ENVIRON_OK ) {
250
250
return res ;
@@ -262,7 +262,7 @@ STATIC os_environ_err_t read_string_value(file_arg *active_file, vstr_t *buf) {
262
262
}
263
263
264
264
// Read a numeric value (non-quoted value) as a string
265
- STATIC os_environ_err_t read_bare_value (file_arg * active_file , vstr_t * buf , int first_character ) {
265
+ STATIC os_getenv_err_t read_bare_value (file_arg * active_file , vstr_t * buf , int first_character ) {
266
266
int character = first_character ;
267
267
while (true) {
268
268
switch (character ) {
@@ -292,13 +292,13 @@ STATIC mp_int_t read_value(file_arg *active_file, vstr_t *buf, bool *quoted) {
292
292
}
293
293
}
294
294
295
- STATIC os_environ_err_t os_environ_get_key_vstr (const char * path , const char * key , vstr_t * buf , bool * quoted ) {
295
+ STATIC os_getenv_err_t os_environ_get_key_vstr (const char * path , const char * key , vstr_t * buf , bool * quoted ) {
296
296
file_arg active_file ;
297
297
if (!open_file (path , & active_file )) {
298
298
return ENVIRON_ERR_OPEN ;
299
299
}
300
300
301
- os_environ_err_t result = ENVIRON_ERR_NOT_FOUND ;
301
+ os_getenv_err_t result = ENVIRON_ERR_NOT_FOUND ;
302
302
while (!is_eof (& active_file )) {
303
303
if (key_matches (& active_file , key )) {
304
304
result = read_value (& active_file , buf , quoted );
@@ -308,10 +308,10 @@ STATIC os_environ_err_t os_environ_get_key_vstr(const char *path, const char *ke
308
308
return result ;
309
309
}
310
310
311
- STATIC os_environ_err_t os_environ_get_key_buf_terminated (const char * key , char * value , size_t value_len , bool * quoted ) {
311
+ STATIC os_getenv_err_t os_environ_get_key_buf_terminated (const char * key , char * value , size_t value_len , bool * quoted ) {
312
312
vstr_t buf ;
313
313
vstr_init_fixed_buf (& buf , value_len , value );
314
- os_environ_err_t result = os_environ_get_key_vstr (ENVIRON_PATH , key , & buf , quoted );
314
+ os_getenv_err_t result = os_environ_get_key_vstr (ENVIRON_PATH , key , & buf , quoted );
315
315
316
316
if (result == ENVIRON_OK ) {
317
317
vstr_add_byte_nonstd (& buf , 0 );
@@ -323,16 +323,16 @@ STATIC os_environ_err_t os_environ_get_key_buf_terminated(const char *key, char
323
323
return result ;
324
324
}
325
325
326
- os_environ_err_t common_hal_os_getenv_str (const char * key , char * value , size_t value_len ) {
326
+ os_getenv_err_t common_hal_os_getenv_str (const char * key , char * value , size_t value_len ) {
327
327
bool quoted ;
328
- os_environ_err_t result = os_environ_get_key_buf_terminated (key , value , value_len , & quoted );
328
+ os_getenv_err_t result = os_environ_get_key_buf_terminated (key , value , value_len , & quoted );
329
329
if (result == ENVIRON_OK && !quoted ) {
330
330
result = ENVIRON_ERR_UNEXPECTED | value [0 ];
331
331
}
332
332
return result ;
333
333
}
334
334
335
- STATIC void throw__environ_error (os_environ_err_t error ) {
335
+ STATIC void throw__environ_error (os_getenv_err_t error ) {
336
336
if (error == ENVIRON_OK ) {
337
337
return ;
338
338
}
@@ -366,7 +366,7 @@ mp_obj_t common_hal_os_getenv_path(const char *path, const char *key, mp_obj_t d
366
366
bool quoted ;
367
367
368
368
vstr_init (& buf , 64 );
369
- os_environ_err_t result = os_environ_get_key_vstr (path , key , & buf , & quoted );
369
+ os_getenv_err_t result = os_environ_get_key_vstr (path , key , & buf , & quoted );
370
370
if (result == ENVIRON_ERR_NOT_FOUND ) {
371
371
return default_ ;
372
372
}
@@ -383,10 +383,10 @@ mp_obj_t common_hal_os_getenv(const char *key, mp_obj_t default_) {
383
383
return common_hal_os_getenv_path (ENVIRON_PATH , key , default_ );
384
384
}
385
385
386
- os_environ_err_t common_hal_os_environ_get_key_int (const char * key , mp_int_t * value ) {
386
+ os_getenv_err_t common_hal_os_environ_get_key_int (const char * key , mp_int_t * value ) {
387
387
char buf [16 ];
388
388
bool quoted ;
389
- os_environ_err_t result = os_environ_get_key_buf_terminated (key , buf , sizeof (buf ), & quoted );
389
+ os_getenv_err_t result = os_environ_get_key_buf_terminated (key , buf , sizeof (buf ), & quoted );
390
390
if (result != ENVIRON_OK ) {
391
391
return result ;
392
392
}
0 commit comments