]> git.sur5r.net Git - cc65/blob - libsrc/common/getenv.s
Changed most "backticks" (grave accents) into apostrophes.
[cc65] / libsrc / common / getenv.s
1 ;
2 ; Ullrich von Bassewitz, 2005-04-21
3 ;
4 ; char* __fastcall__ getenv (const char* name);
5 ;
6 ; Beware: putenv() knows about zero page usage in this module!
7 ;
8
9         .export _getenv
10         .import __environ, __envcount
11         .import searchenv
12         .import return0
13         .import ptr1:zp, ptr3:zp, tmp1:zp
14
15 .code
16
17 ;----------------------------------------------------------------------------
18 ; getenv()
19
20 .proc   _getenv
21
22         sta     ptr1
23         stx     ptr1+1                  ; Save name
24
25 ; Search for the string in the environment. searchenv will set the N flag if
26 ; the string is not found, otherwise X contains the index of the entry, ptr3
27 ; contains the entry and Y the offset of the '=' in the string.
28
29         jsr     searchenv
30         bpl     found
31         jmp     return0                 ; Not found, return NULL
32
33 ; Found the entry. Calculate the pointer to the right side of the environment
34 ; variable. Because we want to skip the '=', we will set the carry.
35
36 found:  ldx     ptr3+1                  ; High byte of result
37         tya
38         sec
39         adc     ptr3
40         bcc     @L9
41         inx
42 @L9:    rts
43
44 .endproc
45
46