"Fossies" - the Fresh Open Source Software Archive

Member "darktable-2.6.3/src/common/grealpath.h" (20 Oct 2019, 1286 Bytes) of package /linux/misc/darktable-2.6.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "grealpath.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  This code is taken from http://git.gnome.org/browse/gobject-introspection/tree/giscanner/grealpath.h .
    3  According to http://git.gnome.org/browse/gobject-introspection/tree/COPYING it's licensed under the LGPLv2+.
    4 */
    5 
    6 #pragma once
    7 
    8 #include <stdlib.h>
    9 
   10 /**
   11  * g_realpath:
   12  *
   13  * this should be a) filled in for win32 and b) put in glib...
   14  */
   15 
   16 static inline gchar *g_realpath(const char *path)
   17 {
   18 #ifndef _WIN32
   19 #ifndef PATH_MAX
   20 #define PATH_MAX 4096
   21 #endif
   22   char buffer[PATH_MAX] = { 0 };
   23   if(realpath(path, buffer))
   24     return g_strdup(buffer);
   25   else
   26     return NULL;
   27 #else
   28   char *buffer;
   29   char dummy;
   30   int rc, len;
   31 
   32   rc = GetFullPathNameA(path, 1, &dummy, NULL);
   33 
   34   if(rc == 0)
   35   {
   36     /* Weird failure, so just return the input path as such */
   37     return g_strdup(path);
   38   }
   39 
   40   len = rc + 1;
   41   buffer = g_malloc(len);
   42 
   43   rc = GetFullPathNameA(path, len, buffer, NULL);
   44 
   45   if(rc == 0 || rc > len)
   46   {
   47     /* Weird failure again */
   48     g_free(buffer);
   49     return g_strdup(path);
   50   }
   51 
   52   return buffer;
   53 #endif
   54 }
   55 
   56 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
   57 // vim: shiftwidth=2 expandtab tabstop=2 cindent
   58 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;