Windows Compatability Functions

Name

Windows Compatability Functions -- 

Synopsis


#include <glib.h>


#define     MAXPATHLEN
#define     NAME_MAX
typedef     pid_t;
#define     pipe                            (phandles)
#define     ftruncate                       (fd, size)
#define     opendir
#define     readdir
#define     rewinddir
#define     closedir
gchar*      g_win32_error_message           (gint error);
gchar*      g_win32_getlocale               (void);
gchar*      g_win32_get_package_installation_directory
                                            (gchar *package,
                                             gchar *dll_name);
gchar*      g_win32_get_package_installation_subdirectory
                                            (gchar *package,
                                             gchar *dll_name,
                                             gchar *subdir);

Description

Details

MAXPATHLEN

#define MAXPATHLEN 1024

Provided for UNIX emulation on Windows; equivalent to UNIX macro MAXPATHLEN, which is the maximum length of a filename (including full path).


NAME_MAX

#    define NAME_MAX 255

Provided for UNIX emulation on Windows; equivalent to UNIX macro NAME_MAX, which is the maximum length of a single path component. i.e. just the "foo" in "/usr/bin/foo".


pid_t

typedef int pid_t;

Provided for UNIX emulation on Windows; process ID type.


pipe()

#define pipe(phandles)	_pipe (phandles, 4096, _O_BINARY)

Provided for UNIX emulation on Windows; see documentation for pipe() in any UNIX manual.

phandles : 


ftruncate()

#    define ftruncate(fd, size)	g_win32_ftruncate (fd, size)

Provided for UNIX emulation on Windows; see documentation for ftruncate() in any UNIX manual.

fd : 
size : 


opendir

#    define opendir		g_win32_opendir

Provided for UNIX emulation on Windows; see documentation for opendir() in any UNIX manual.


readdir

#    define readdir		g_win32_readdir

Provided for UNIX emulation on Windows; see documentation for readdir() in any UNIX manual.


rewinddir

#    define rewinddir		g_win32_rewinddir

Provided for UNIX emulation on Windows; see documentation for rewinddir() in any UNIX manual.


closedir

#    define closedir		g_win32_closedir

Provided for UNIX emulation on Windows; see documentation for closedir() in any UNIX manual.


g_win32_error_message ()

gchar*      g_win32_error_message           (gint error);

Translate a Win32 error code (as returned by GetLastError()) into the corresponding message. The message is either language neutral, or in the thread's language, or the user's language, the system's langauge, or US English (see docs for FormatMessage). The returned string should be deallocated with g_free().

error : error code
Returns : allocated error message


g_win32_getlocale ()

gchar*      g_win32_getlocale               (void);

The setlocale in the Microsoft C library uses locale names of the form "English_United States.1252" etc. We want the Unixish standard form "en", "zh_TW" etc. This function gets the current thread locale from Windows and returns it as a string of the above form for use in forming file names etc. The returned string should be deallocated with g_free().

Returns : allocated locale name


g_win32_get_package_installation_directory ()

gchar*      g_win32_get_package_installation_directory
                                            (gchar *package,
                                             gchar *dll_name);

Try to determine the installation directory for a software package. Typically used by GNU software packages.

package should be a short identifier for the package. Typically it is the same identifier as used for GETTEXT_PACKAGE in software configured accoring to GNU standards. The function first looks in the Windows Registry for the value InstallationDirectory in the key HKLM\Software\package, and if that value exists and is a string, returns that.

If package is NULL, or the above value isn't found in the Registry, but dll_name is non-NULL, it should name a DLL loaded into the current process. Typically that would be the name of the DLL calling this function, looking for its installation directory. The function then asks Windows what directory that DLL was loaded from. If that directory's last component is "bin" or "lib", the parent directory is returned, otherwise the directory itself. If that DLL isn't loaded, the function proceeds as if dll_name was NULL.

If both package and dll_name are NULL, the directory from where the main executable of the process was loaded is uses instead in the same way as above.

The return value should be freed with g_free() when not needed any longer. */

gchar * g_win32_get_package_installation_directory (gchar *package, gchar *dll_name) { static GHashTable *package_dirs = NULL; gchar *result = NULL; gchar *key; HKEY reg_key = NULL; DWORD type; DWORD nbytes;

if (package != NULL) { if (package_dirs == NULL) package_dirs = g_hash_table_new (g_str_hash, g_str_equal); result = g_hash_table_lookup (package_dirs, package); if (result && result[0]) return g_strdup (result); key = g_strconcat ("Software\\", package, NULL); nbytes = 0; if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS && RegQueryValueEx (reg_key, "InstallationDirectory", 0, &type, NULL, &nbytes) == ERROR_SUCCESS && type == REG_SZ) { result = g_malloc (nbytes + 1); RegQueryValueEx (reg_key, "InstallationDirectory", 0, &type, result, &nbytes); result[nbytes] = '\0'; }

if (reg_key != NULL) RegCloseKey (reg_key); g_free (key); } if (result) { g_hash_table_insert (package_dirs, package, result); return g_strdup (result); }

if (dll_name != NULL) result = get_package_directory_from_module (dll_name);

if (result == NULL) result = get_package_directory_from_module (NULL);

return result; }

/** g_win32_get_package_installation_subdirectory: package: An identifier for a software package, or NULL dll_name: The name of a DLL that a package provides, or NULL subdir: A subdirectory of the package installation directory.

package : An identifier for a software package, or NULL
dll_name : The name of a DLL that a package provides, or NULL
Returns :a string containg the path of the subdirectory subdir in the return value from calling g_win32_get_package_installation_directory() with the package and dll_name parameters. The return value should be freed with g_free() when no longer needed.


g_win32_get_package_installation_subdirectory ()

gchar*      g_win32_get_package_installation_subdirectory
                                            (gchar *package,
                                             gchar *dll_name,
                                             gchar *subdir);

package : 
dll_name : 
subdir : 
Returns :