errno for linux and macOS

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

errno for linux and macOS

Post by mk-soft »

We can't import threaded last error errno

Code: Select all

ImportC ""
  errno
  ;sock_errno() ; macOS
EndImport
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: errno for linux and macOS

Post by idle »

can you do it with inlineC and just assign it to a variable?

Code: Select all

global errno  
!v_errno = errno; 
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: errno for linux and macOS

Post by mk-soft »

Its now works with C-Backend, but not with ASM :?: :!:

Code: Select all

;-TOP
; By mk-soft, v1.01.1, 08.01.2023
; Not work with ASM

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Macro GetLastError()
    GetLastError_()
  EndMacro
CompilerElse
  CompilerIf #PB_Compiler_Backend = #PB_Backend_C
    Procedure GetLastError()
      !#include "errno.h"
      !extern int errno;
      Protected r1
      !v_r1=errno;
      ProcedureReturn r1
    EndProcedure
  CompilerElse
    ImportC ""
      errno
    EndImport
    ;!extrn errno;
    Procedure GetLastError()
      Protected r1
      r1 = errno
      ProcedureReturn r1
    EndProcedure
  CompilerEndIf
CompilerEndIf

; ----

Procedure.s GetLastNetworkError()
  Protected r1.s, errcode, *buffer, len
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      errcode = WSAGetLastError_()
      len = FormatMessage_(#FORMAT_MESSAGE_ALLOCATE_BUFFER|#FORMAT_MESSAGE_FROM_SYSTEM|#FORMAT_MESSAGE_IGNORE_INSERTS, 0, errCode, 0, @*buffer,0,0) 
      If len 
        r1 = PeekS(*buffer)
        LocalFree_(*buffer)
      EndIf
    CompilerDefault
      *buffer = strerror_(GetLastError())
      r1 = PeekS(*buffer, -1, #PB_Ascii)
  CompilerEndSelect
  ProcedureReturn r1
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  
  r1.s = GetLastNetworkError()
  Debug r1
  
CompilerEndIf
Linux ASM Linker Error
/usr/bin/ld: errno: TLS definition in /lib/x86_64-linux-gnu/libc.so.6 section .tbss mismatches non-TLS reference in purebasic.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: error adding symbols: bad value
collect2: error: ld returned 1 exit status
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply