* enc/trans/utf_16_32.erb.c (fun_so_from_utf_32le): implemented.
[ruby-svn.git] / missing / os2.c
blob3448cdc281b1c3de05e1c50f0e2f3c5e6b5793e7
1 /* os/2 compatibility functions -- follows Ruby's license */
3 #include "ruby.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <fcntl.h>
7 #include <process.h>
8 #include <limits.h>
9 #include <errno.h>
11 #define INCL_DOS
12 #include <os2.h>
14 int
15 chown(char *path, int owner, int group)
17 return 0;
20 #if 0
21 int
22 link(char *from, char *to)
24 return -1;
26 #endif
28 #if defined(EMX_REPLACE_GETCWD) && (EMX_REPLACE_GETCWD) \
29 || defined(EMX_REPLACE_CHDIR) && (EMX_REPLACE_CHDIR)
30 #include <unistd.h>
32 #if defined(EMX_REPLACE_GETCWD) && (EMX_REPLACE_GETCWD)
33 /* to handle the drive letter and DBCS characters within a given path */
34 char *
35 getcwd(char *path, size_t len)
37 return _getcwd2(path, (int)len);
39 #endif
41 #if defined(EMX_REPLACE_CHDIR) && (EMX_REPLACE_CHDIR)
42 /* to handle the drive letter and DBCS characters within a given path */
43 int
44 chdir(__const__ char *path)
46 return _chdir2(path);
48 #endif
49 #endif
51 typedef char* CHARP;
53 int
54 do_spawn(cmd)
55 char *cmd;
57 register char **a;
58 register char *s;
59 char **argv;
60 char *shell, *sw, *cmd2;
61 int status;
63 if ((shell = getenv("RUBYSHELL")) != NULL && *shell != '\0') {
64 s = shell;
66 *s = isupper(*s) ? tolower(*s) : *s;
67 while (*++s);
68 if (strstr(shell, "cmd") || strstr(shell, "4os2"))
69 sw = "/c";
70 else
71 sw = "-c";
72 } else if ((shell = getenv("SHELL")) != NULL && *shell != '\0') {
73 s = shell;
75 *s = isupper(*s) ? tolower(*s) : *s;
76 while (*++s);
77 if (strstr(shell, "cmd") || strstr(shell, "4os2"))
78 sw = "/c";
79 else
80 sw = "-c";
81 } else if ((shell = getenv("COMSPEC")) != NULL && *shell != '\0') {
82 s = shell;
84 *s = isupper(*s) ? tolower(*s) : *s;
85 while (*++s);
86 if (strstr(shell, "cmd") || strstr(shell, "4os2"))
87 sw = "/c";
88 else
89 sw = "-c";
91 /* see if there are shell metacharacters in it */
92 /*SUPPRESS 530*/
93 /* for (s = cmd; *s && isalpha(*s); s++) ;
94 if (*s == '=')
95 goto doshell; */
96 for (s = cmd; *s; s++) {
97 if (*sw == '-' && *s != ' ' &&
98 !isalpha(*s) && index("$&*(){}[]'\";\\|?<>~`\n",*s)) {
99 if (*s == '\n' && !s[1]) {
100 *s = '\0';
101 break;
103 goto doshell;
104 } else if (*sw == '/' && *s != ' ' &&
105 !isalpha(*s) && index("^()<>|&\n",*s)) {
106 if (*s == '\n' && !s[1]) {
107 *s = '\0';
108 break;
110 doshell:
111 status = spawnlp(P_WAIT,shell,shell,sw,cmd,(char*)NULL);
112 return status;
115 argv = ALLOC_N(CHARP,(strlen(cmd) / 2 + 2));
116 cmd2 = ALLOC_N(char, (strlen(cmd) + 1));
117 strcpy(cmd2, cmd);
118 a = argv;
119 for (s = cmd2; *s;) {
120 while (*s && isspace(*s)) s++;
121 if (*s)
122 *(a++) = s;
123 while (*s && !isspace(*s)) s++;
124 if (*s)
125 *s++ = '\0';
127 *a = NULL;
128 if (argv[0]) {
129 if ((status = spawnvp(P_WAIT, argv[0], argv)) == -1) {
130 free(argv);
131 free(cmd2);
132 return -1;
135 free(cmd2);
136 free(argv);
137 return status;