Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
grealpath.h
Go to the documentation of this file.
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#include <stdio.h>
10#include <string.h>
11#include <errno.h>
12#include <glib.h>
13
14#ifdef _WIN32
15#include <fileapi.h>
16#endif
17
24static inline gchar *g_realpath(const char *path)
25{
26#ifndef _WIN32
27#ifndef PATH_MAX
28#define PATH_MAX 4096
29#endif
30 char buffer[PATH_MAX] = { 0 };
31
32 char* res = realpath(path, buffer);
33
34 if(res)
35 {
36 return g_strdup(buffer);
37 }
38 else
39 {
40 fprintf(stderr, "path lookup '%s' fails with: '%s'\n", path, strerror(errno));
41 exit(EXIT_FAILURE);
42 }
43#else
44 char *buffer;
45 char dummy;
46 int rc, len;
47
48 rc = GetFullPathNameA(path, 1, &dummy, NULL);
49
50 if(rc == 0)
51 {
52 /* Weird failure, so just return the input path as such */
53 return g_strdup(path);
54 }
55
56 len = rc + 1;
57 buffer = g_malloc(len);
58
59 rc = GetFullPathNameA(path, len, buffer, NULL);
60
61 if(rc == 0 || rc > len)
62 {
63 /* Weird failure again */
64 g_free(buffer);
65 return g_strdup(path);
66 }
67
68 return buffer;
69#endif
70}
71
72// clang-format off
73// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
74// vim: shiftwidth=2 expandtab tabstop=2 cindent
75// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
76// clang-format on
77
dt_iop_colorout_gui_data_t dummy
Definition colorout.c:803
static gchar * g_realpath(const char *path)
Definition grealpath.h:24
#define PATH_MAX