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 file is part of darktable,
3 Copyright (C) 2013-2014, 2016 Tobias Ellinghaus.
4 Copyright (C) 2014 Roman Lebedev.
5 Copyright (C) 2020 Andreas Schneider.
6 Copyright (C) 2020 David-Tillmann Schaefer.
7 Copyright (C) 2021 Pascal Obry.
8 Copyright (C) 2022 Martin Baƙinka.
9
10 darktable is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 darktable is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with darktable. If not, see <http://www.gnu.org/licenses/>.
22*/
23/*
24 This code is taken from http://git.gnome.org/browse/gobject-introspection/tree/giscanner/grealpath.h .
25 According to http://git.gnome.org/browse/gobject-introspection/tree/COPYING it's licensed under the LGPLv2+.
26*/
27
28#pragma once
29
30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
33#include <errno.h>
34#include <glib.h>
35
36#ifdef _WIN32
37#include <fileapi.h>
38#endif
39
46static inline gchar *g_realpath(const char *path)
47{
48#ifndef _WIN32
49#ifndef PATH_MAX
50#define PATH_MAX 4096
51#endif
52 char buffer[PATH_MAX] = { 0 };
53
54 char* res = realpath(path, buffer);
55
56 if(res)
57 {
58 return g_strdup(buffer);
59 }
60 else
61 {
62 fprintf(stderr, "path lookup '%s' fails with: '%s'\n", path, strerror(errno));
63 exit(EXIT_FAILURE);
64 }
65#else
66 char *buffer;
67 char dummy;
68 int rc, len;
69
70 rc = GetFullPathNameA(path, 1, &dummy, NULL);
71
72 if(rc == 0)
73 {
74 /* Weird failure, so just return the input path as such */
75 return g_strdup(path);
76 }
77
78 len = rc + 1;
79 buffer = g_malloc(len);
80
81 rc = GetFullPathNameA(path, len, buffer, NULL);
82
83 if(rc == 0 || rc > len)
84 {
85 /* Weird failure again */
86 g_free(buffer);
87 buffer = NULL;
88 return g_strdup(path);
89 }
90
91 return buffer;
92#endif
93}
94
95// clang-format off
96// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
97// vim: shiftwidth=2 expandtab tabstop=2 cindent
98// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
99// clang-format on
dt_iop_colorout_gui_data_t dummy
Definition colorout.c:830
static gchar * g_realpath(const char *path)
Definition grealpath.h:46
#define PATH_MAX