Ottenere la lista di tutte le variabili d'ambiente nel proprio sistema mediante le risorse del API di GLIB-2.0

Da Gambas-it.org - Wikipedia.

La funzione esterna "g_get_environ()" del API di GLIB-2.0 consente di ottenere una lista di tutte le variabili d'ambiente nel nostro sistema.

E' necessario avere installata e richiamare in Gambas la libreria condivisa: "libglib-2.0.so.0.7800.3 ".

Mostriamo un semplice esempio:

Library "libglib-2.0:0.7800.3"

' gchar ** g_get_environ (void)
' Gets the list of environment variables for the current process.
Private Extern g_get_environ() As Pointer

' void g_strfreev (gchar **str_array)
' Frees a NULL-terminated array of strings.
Private Extern g_strfreev(str_array As Pointer)


Public Sub Main()
 
 Dim en As Pointer
 Dim i As Integer
 Dim s As String
  
 en = g_get_environ()
 If en == 0 Then Error.Raise("Errore !")

 Repeat
   s = String@(Pointer@(en + i))
   Print s
   i += SizeOf(gb.Pointer)
 Until s == Null

 g_strfreev(en)
 
End


Riferimenti