forked from holzschu/ios_system
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ios_error.h
122 lines (110 loc) · 3.99 KB
/
ios_error.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// error.h
// shell_cmds_ios
//
// Created by Nicolas Holzschuch on 16/06/2017.
// Copyright © 2017 Nicolas Holzschuch. All rights reserved.
//
#ifndef ios_error_h
#define ios_error_h
#ifdef __cplusplus
extern "C" {
#endif
#include <unistd.h>
#include <stdarg.h>
#include <stdio.h>
#include <pthread.h>
/* #define errx compileError
#define err compileError
#define warn compileError
#define warnx compileError
#ifndef printf
#define printf(...) fprintf (thread_stdout, ##__VA_ARGS__)
#endif */
#define putchar(a) fputc(a, thread_stdout)
#define getchar() fgetc(thread_stdin)
// these functions are defined differently in C++. The #define approach breaks things.
#ifndef __cplusplus
#define getwchar() fgetwc(thread_stdin)
#define putwchar(a) fputwc(a, thread_stdout)
// iswprint depends on the given locale, and setlocale() fails on iOS:
#define iswprint(a) 1
#define write ios_write
#define fwrite ios_fwrite
#define puts ios_puts
#define fputs ios_fputs
#define fputc ios_fputc
#define putw ios_putw
#define putp ios_putp
#define fflush ios_fflush
#define abort() ios_exit(1)
#endif
// Thread-local input and output streams
extern __thread FILE* thread_stdin;
extern __thread FILE* thread_stdout;
extern __thread FILE* thread_stderr;
#define exit ios_exit
#define _exit ios_exit
#define kill ios_killpid
#define _kill ios_killpid
#define killpg ios_killpid
#define popen ios_popen
#define pclose fclose
#define system ios_system
#define execv ios_execv
#define execvp ios_execv
#define execve ios_execve
#define dup2 ios_dup2
#define getenv ios_getenv
#define setenv ios_setenv
#define unsetenv ios_unsetenv
#define putenv ios_putenv
#define fchdir ios_fchdir
extern int ios_executable(const char* cmd); // is this command part of the "shell" commands?
extern int ios_system(const char* inputCmd); // execute this command (executable file or builtin command)
extern FILE *ios_popen(const char *command, const char *type); // Execute this command and pipe the result
extern int ios_kill(void); // kill the current running command
extern int ios_killpid(pid_t pid, int sig); // kill the current running command
extern void ios_exit(int errorCode) __dead2; // set error code and exits from the thread.
extern int ios_execv(const char *path, char* const argv[]);
extern int ios_execve(const char *path, char* const argv[], char** envlist);
extern int ios_dup2(int fd1, int fd2);
extern char * ios_getenv(const char *name);
extern int ios_setenv(const char* variableName, const char* value, int overwrite);
int ios_unsetenv(const char* variableName);
extern int ios_putenv(char *string);
extern char** environmentVariables(pid_t pid);
extern int ios_isatty(int fd);
extern pthread_t ios_getLastThreadId(void); // deprecated
extern pthread_t ios_getThreadId(pid_t pid);
extern void ios_storeThreadId(pthread_t thread);
extern void ios_releaseThread(pthread_t thread);
extern void ios_releaseThreadId(pid_t pid);
extern pid_t ios_currentPid(void);
extern int ios_getCommandStatus(void);
extern const char* ios_progname(void);
extern pid_t ios_fork(void);
extern void ios_waitpid(pid_t pid);
extern void ios_signal(int signal);
extern int ios_fchdir(const int fd);
extern ssize_t ios_write(int fildes, const void *buf, size_t nbyte);
extern size_t ios_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
extern int ios_puts(const char *s);
extern int ios_fputs(const char* s, FILE *stream);
extern int ios_fputc(int c, FILE *stream);
extern int ios_putw(int w, FILE *stream);
extern int ios_fflush(FILE *stream);
extern int ios_gettty(void);
extern int ios_opentty(void);
extern void ios_closetty(void);
extern void ios_stopInteractive(void);
extern void ios_startInteractive(void);
extern int ios_storeInteractive(void);
// Communication between dash and ios_system:
extern const char* ios_expandtilde(const char *login);
extern void ios_activateChildStreams(FILE** old_stdin, FILE** old_stdout, FILE ** old_stderr);
extern const char* ios_getBookmarkedVersion(const char* p);
#ifdef __cplusplus
}
#endif
#endif /* ios_error_h */