Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/games/alex4/files/patch-unix.c
16461 views
1
--- unix.c.orig 2016-06-14 16:25:53 UTC
2
+++ unix.c
3
@@ -0,0 +1,87 @@
4
+#ifdef __unix__
5
+#include <stdio.h>
6
+#include <stdlib.h>
7
+#include <unistd.h>
8
+#include <pwd.h>
9
+#include <errno.h>
10
+#include <sys/types.h>
11
+#include <sys/stat.h>
12
+#if defined(__DECC) && defined(VMS)
13
+#include <unixlib.h>
14
+static char *vms_to_unix_buffer = NULL;
15
+static int convert_vms_to_unix(char *vms_dir_name)
16
+{
17
+ vms_to_unix_buffer = vms_dir_name;
18
+}
19
+#endif
20
+
21
+char *get_homedir(void)
22
+{
23
+ struct passwd *pw;
24
+ char *home;
25
+
26
+ home = getenv("HOME");
27
+ if (home)
28
+ return home;
29
+
30
+ if (!(pw = getpwuid(getuid())))
31
+ {
32
+ fprintf(stderr, "Who are you? Not found in passwd database!!\n");
33
+ return NULL;
34
+ }
35
+
36
+#if defined(__DECC) && defined(VMS)
37
+ /* Convert The OpenVMS Formatted "$HOME" Directory Path Into Unix
38
+ Format. */
39
+ decc$from_vms(pw->pw_dir, convert_vms_to_unix, 1);
40
+ return vms_to_unix_buffer;
41
+#else
42
+ return pw->pw_dir;
43
+#endif
44
+}
45
+//-----------------------------------------------------------------------------
46
+int check_and_create_dir(const char *name)
47
+{
48
+ struct stat stat_buffer;
49
+
50
+ if (stat(name, &stat_buffer))
51
+ {
52
+ /* error check if it doesn't exist or something else is wrong */
53
+ if (errno == ENOENT)
54
+ {
55
+ /* doesn't exist letts create it ;) */
56
+#ifdef BSD43
57
+ if (mkdir(name, 0775))
58
+#else
59
+ if (mkdir(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH))
60
+#endif
61
+ {
62
+ fprintf(stderr, "Error creating dir %s", name);
63
+ perror(" ");
64
+ return -1;
65
+ }
66
+ }
67
+ else
68
+ {
69
+ /* something else went wrong yell about it */
70
+ fprintf(stderr, "Error opening %s", name);
71
+ perror(" ");
72
+ return -1;
73
+ }
74
+ }
75
+ else
76
+ {
77
+ /* file exists check it's a dir otherwise yell about it */
78
+#ifdef BSD43
79
+ if (!(S_IFDIR & stat_buffer.st_mode))
80
+#else
81
+ if (!S_ISDIR(stat_buffer.st_mode))
82
+#endif
83
+ {
84
+ fprintf(stderr,"Error %s exists but isn't a dir\n", name);
85
+ return -1;
86
+ }
87
+ }
88
+ return 0;
89
+}
90
+#endif
91
92