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