"Fossies" - the Fresh Open Source Software Archive

Member "fasm/tools/libc/system.inc" (9 Feb 2020, 1508 Bytes) of package /linux/misc/fasm-1.73.22.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 extrn malloc
    3 extrn getenv
    4 extrn fopen
    5 extrn fclose
    6 extrn fread
    7 extrn fwrite
    8 extrn fseek
    9 extrn ftell
   10 extrn time
   11 extrn exit
   12 extrn 'free' as libc_free
   13 extrn 'write' as libc_write
   14 
   15 alloc:
   16     ccall   malloc,eax
   17     test    eax,eax
   18     jz  allocation_failed
   19     clc
   20     ret
   21       allocation_failed:
   22     stc
   23     ret
   24 free:
   25     ccall   libc_free,eax
   26     ret
   27 display_string:
   28     lodsb
   29     or  al,al
   30     jz  string_displayed
   31     mov dl,al
   32     call    display_character
   33     jmp display_string
   34       string_displayed:
   35     ret
   36     display_character:
   37     mov [character],dl
   38     ccall   libc_write,[display_handle],character,1
   39     ret
   40 open:
   41     push    esi edi ebp
   42     call    adapt_path
   43     ccall   fopen,buffer,open_mode
   44     pop ebp edi esi
   45     or  eax,eax
   46     jz  file_error
   47     mov ebx,eax
   48     clc
   49     ret
   50     adapt_path:
   51     mov esi,edx
   52     mov edi,buffer
   53       copy_path:
   54     lods    byte [esi]
   55     cmp al,'\'
   56     jne path_char_ok
   57     mov al,'/'
   58       path_char_ok:
   59     stos    byte [edi]
   60     or  al,al
   61     jnz copy_path
   62     cmp edi,buffer+1000h
   63     ja  not_enough_memory
   64     ret
   65 create:
   66     push    esi edi ebp
   67     call    adapt_path
   68     ccall   fopen,buffer,create_mode
   69     pop ebp edi esi
   70     or  eax,eax
   71     jz  file_error
   72     mov ebx,eax
   73     clc
   74     ret
   75 close:
   76     ccall   fclose,ebx
   77     ret
   78 read:
   79     push    ebx ecx edx esi edi
   80     ccall   fread,edx,1,ecx,ebx
   81     pop edi esi edx ecx ebx
   82     cmp eax,ecx
   83     jne file_error
   84     clc
   85     ret
   86     file_error:
   87     stc
   88     ret
   89 write:
   90     push    ebx ecx edx esi edi
   91     ccall   fwrite,edx,1,ecx,ebx
   92     pop edi esi edx ecx ebx
   93     cmp eax,ecx
   94     jne file_error
   95     clc
   96     ret
   97 lseek:
   98     push    ebx
   99     movzx   eax,al
  100     ccall   fseek,ebx,edx,eax
  101     mov ebx,[esp]
  102     ccall   ftell,ebx
  103     pop ebx
  104     ret
  105 
  106 open_mode db 'r',0
  107 create_mode db 'w',0