@@ -187,13 +187,13 @@ STATIC os_getenv_err_t read_unicode_escape(file_arg *active_file, int sz, vstr_t
187
187
char * end ;
188
188
unsigned long c = strtoul (hex_buf , & end , 16 );
189
189
if (end != & hex_buf [sz ]) {
190
- return ENVIRON_ERR_UNEXPECTED | * end ;
190
+ return GETENV_ERR_UNEXPECTED | * end ;
191
191
}
192
192
if (c >= 0x110000 ) {
193
- return ENVIRON_ERR_UNICODE ;
193
+ return GETENV_ERR_UNICODE ;
194
194
}
195
195
vstr_add_char_nonstd (buf , c );
196
- return ENVIRON_OK ;
196
+ return GETENV_OK ;
197
197
}
198
198
199
199
// Read a quoted string
@@ -203,7 +203,7 @@ STATIC os_getenv_err_t read_string_value(file_arg *active_file, vstr_t *buf) {
203
203
switch (character ) {
204
204
case 0 :
205
205
case '\n' :
206
- return ENVIRON_ERR_UNEXPECTED | character ;
206
+ return GETENV_ERR_UNEXPECTED | character ;
207
207
208
208
case '"' :
209
209
character = consume_whitespace (active_file );
@@ -212,17 +212,17 @@ STATIC os_getenv_err_t read_string_value(file_arg *active_file, vstr_t *buf) {
212
212
next_line (active_file );
213
213
MP_FALLTHROUGH ;
214
214
case '\n' :
215
- return ENVIRON_OK ;
215
+ return GETENV_OK ;
216
216
default :
217
- return ENVIRON_ERR_UNEXPECTED | character ;
217
+ return GETENV_ERR_UNEXPECTED | character ;
218
218
}
219
219
220
220
case '\\' :
221
221
character = get_next_byte (active_file );
222
222
switch (character ) {
223
223
case 0 :
224
224
case '\n' :
225
- return ENVIRON_ERR_UNEXPECTED | character ;
225
+ return GETENV_ERR_UNEXPECTED | character ;
226
226
case 'b' :
227
227
character = '\b' ;
228
228
break ;
@@ -246,7 +246,7 @@ STATIC os_getenv_err_t read_string_value(file_arg *active_file, vstr_t *buf) {
246
246
int sz = (character == 'u' ) ? 4 : 8 ;
247
247
os_getenv_err_t res ;
248
248
res = read_unicode_escape (active_file , sz , buf );
249
- if (res != ENVIRON_OK ) {
249
+ if (res != GETENV_OK ) {
250
250
return res ;
251
251
}
252
252
continue ;
@@ -267,12 +267,12 @@ STATIC os_getenv_err_t read_bare_value(file_arg *active_file, vstr_t *buf, int f
267
267
while (true) {
268
268
switch (character ) {
269
269
case 0 :
270
- return ENVIRON_ERR_UNEXPECTED | character ;
270
+ return GETENV_ERR_UNEXPECTED | character ;
271
271
case '\n' :
272
- return ENVIRON_OK ;
272
+ return GETENV_OK ;
273
273
case '#' :
274
274
next_line (active_file );
275
- return ENVIRON_OK ;
275
+ return GETENV_OK ;
276
276
default :
277
277
vstr_add_byte_nonstd (buf , character );
278
278
}
@@ -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_getenv_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_getenv_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
- return ENVIRON_ERR_OPEN ;
298
+ return GETENV_ERR_OPEN ;
299
299
}
300
300
301
- os_getenv_err_t result = ENVIRON_ERR_NOT_FOUND ;
301
+ os_getenv_err_t result = GETENV_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,35 +308,35 @@ STATIC os_getenv_err_t os_environ_get_key_vstr(const char *path, const char *key
308
308
return result ;
309
309
}
310
310
311
- STATIC os_getenv_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_getenv_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_getenv_err_t result = os_environ_get_key_vstr ( ENVIRON_PATH , key , & buf , quoted );
314
+ os_getenv_err_t result = os_getenv_vstr ( GETENV_PATH , key , & buf , quoted );
315
315
316
- if (result == ENVIRON_OK ) {
316
+ if (result == GETENV_OK ) {
317
317
vstr_add_byte_nonstd (& buf , 0 );
318
318
memcpy (value , buf .buf , MIN (buf .len , value_len ));
319
319
if (buf .len > value_len ) {
320
- result = ENVIRON_ERR_LENGTH ;
320
+ result = GETENV_ERR_LENGTH ;
321
321
}
322
322
}
323
323
return result ;
324
324
}
325
325
326
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_getenv_err_t result = os_environ_get_key_buf_terminated (key , value , value_len , & quoted );
329
- if (result == ENVIRON_OK && !quoted ) {
330
- result = ENVIRON_ERR_UNEXPECTED | value [0 ];
328
+ os_getenv_err_t result = os_getenv_buf_terminated (key , value , value_len , & quoted );
329
+ if (result == GETENV_OK && !quoted ) {
330
+ result = GETENV_ERR_UNEXPECTED | value [0 ];
331
331
}
332
332
return result ;
333
333
}
334
334
335
- STATIC void throw__environ_error (os_getenv_err_t error ) {
336
- if (error == ENVIRON_OK ) {
335
+ STATIC void throw_getenv_error (os_getenv_err_t error ) {
336
+ if (error == GETENV_OK ) {
337
337
return ;
338
338
}
339
- if (error & ENVIRON_ERR_UNEXPECTED ) {
339
+ if (error & GETENV_ERR_UNEXPECTED ) {
340
340
byte character = (error & 0xff );
341
341
mp_print_t print ;
342
342
vstr_t vstr ;
@@ -350,11 +350,11 @@ STATIC void throw__environ_error(os_getenv_err_t error) {
350
350
vstr .len , vstr .buf );
351
351
}
352
352
switch (error ) {
353
- case ENVIRON_ERR_OPEN :
353
+ case GETENV_ERR_OPEN :
354
354
mp_raise_ValueError (translate ("File not found" ));
355
- case ENVIRON_ERR_UNICODE :
355
+ case GETENV_ERR_UNICODE :
356
356
mp_raise_ValueError (translate ("Invalid unicode escape" ));
357
- case ENVIRON_ERR_NOT_FOUND :
357
+ case GETENV_ERR_NOT_FOUND :
358
358
mp_raise_ValueError (translate ("Key not found" ));
359
359
default :
360
360
mp_raise_RuntimeError (translate ("Internal error" ));
@@ -366,11 +366,11 @@ 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_getenv_err_t result = os_environ_get_key_vstr (path , key , & buf , & quoted );
370
- if (result == ENVIRON_ERR_NOT_FOUND ) {
369
+ os_getenv_err_t result = os_getenv_vstr (path , key , & buf , & quoted );
370
+ if (result == GETENV_ERR_NOT_FOUND ) {
371
371
return default_ ;
372
372
}
373
- throw__environ_error (result );
373
+ throw_getenv_error (result );
374
374
375
375
if (quoted ) {
376
376
return mp_obj_new_str_from_vstr (& mp_type_str , & buf );
@@ -380,24 +380,24 @@ mp_obj_t common_hal_os_getenv_path(const char *path, const char *key, mp_obj_t d
380
380
}
381
381
382
382
mp_obj_t common_hal_os_getenv (const char * key , mp_obj_t default_ ) {
383
- return common_hal_os_getenv_path (ENVIRON_PATH , key , default_ );
383
+ return common_hal_os_getenv_path (GETENV_PATH , key , default_ );
384
384
}
385
385
386
- os_getenv_err_t common_hal_os_environ_get_key_int (const char * key , mp_int_t * value ) {
386
+ os_getenv_err_t common_hal_os_getenv_int (const char * key , mp_int_t * value ) {
387
387
char buf [16 ];
388
388
bool quoted ;
389
- os_getenv_err_t result = os_environ_get_key_buf_terminated (key , buf , sizeof (buf ), & quoted );
390
- if (result != ENVIRON_OK ) {
389
+ os_getenv_err_t result = os_getenv_buf_terminated (key , buf , sizeof (buf ), & quoted );
390
+ if (result != GETENV_OK ) {
391
391
return result ;
392
392
}
393
393
if (quoted ) {
394
- return ENVIRON_ERR_UNEXPECTED | '"' ;
394
+ return GETENV_ERR_UNEXPECTED | '"' ;
395
395
}
396
396
char * end ;
397
397
long num = strtol (buf , & end , 0 );
398
398
if (end == buf || * end ) { // If the whole buffer was not consumed it's an error
399
- return ENVIRON_ERR_UNEXPECTED | * end ;
399
+ return GETENV_ERR_UNEXPECTED | * end ;
400
400
}
401
401
* value = (mp_int_t )num ;
402
- return ENVIRON_OK ;
402
+ return GETENV_OK ;
403
403
}
0 commit comments