summaryrefslogtreecommitdiffstats
path: root/loader2/dietstubs.c
blob: 5d319bc6148d5f10e2c5a3b7f157e8490d8d1e4a (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <setjmp.h>
#include <ctype.h>
#include <stdarg.h>
#include <unistd.h>
#ifdef GZLIB
#include "../isys/gzlib/gzlib.h"
#endif

#define WLITE_REDEF_STDC 0
#include <wlite_wchar.h>
#include <wlite_wctype.h>

struct glibc_stat {
    long long st_dev;
    unsigned short int __pad1;
    long st_ino;
    int st_mode;
    int st_nlink;
    int  st_uid;
    int  st_gid;
    long long st_rdev;
    unsigned short int __pad2;
    long st_size;
    long st_blksize;
    long st_blocks;
    long st_atime;
    unsigned long int __unused1;
    long st_mtime;
    unsigned long int __unused2;
    long st_ctime;
    unsigned long int __unused3;
    unsigned long int __unused4;
    unsigned long int __unused5;
};

static void stat_copy(struct stat * from, struct glibc_stat * to) {
    to->st_dev = from->st_dev;
    to->st_ino = from->st_ino;
    to->st_mode = from->st_mode;
    to->st_nlink = from->st_nlink;
    to->st_uid = from->st_uid;
    to->st_gid = from->st_gid;
    to->st_rdev = from->st_rdev;
    to->st_size = from->st_size;
    to->st_blksize = from->st_blksize;
    to->st_blocks = from->st_blocks;
    to->st_atime = from->st_atime;
    to->st_mtime = from->st_mtime;
    to->st_ctime = from->st_ctime;
}

int __xstat (int __ver, __const char *__filename, struct glibc_stat * sb) {
    struct stat s;
    int rc = stat(__filename, &s); 

    if (!rc) stat_copy(&s, sb);

    return rc;
}

int __lxstat (int __ver, __const char *__filename, struct glibc_stat * sb) {
    struct stat s;
    int rc = lstat(__filename, &s); 

    if (!rc) stat_copy(&s, sb);

    return rc;
}

int __fxstat (int __ver, int fd, struct glibc_stat * sb) {
    struct stat s;
    int rc = fstat(fd, &s); 

    if (!rc) stat_copy(&s, sb);

    return rc;
}

extern double strtod (__const char * __nptr, char ** __endptr);

double __strtod_internal (__const char *__restrict __nptr,
				 char **__restrict __endptr, int __group) {
    return strtod(__nptr, __endptr);
}


long int __strtol_internal(const char * nptr, char ** endptr, 
			   int base, int group) {
    return strtol(nptr, endptr, base);
}

unsigned long int __strtoul_internal (__const char *__restrict __nptr,
					 char **__restrict __endptr,
					 int __base, int __group) __THROW {
    return strtoul(__nptr, __endptr, __base);
}

char * __strdup(const char * s) {
    return strdup(s);
}

void __assert_fail (__const char *__assertion, __const char *__file,
			   unsigned int __line, __const char *__function) {
    fprintf(stderr, "%s:%d assertion failed in %s()\n",
	    __file, __line, __function);
    abort();
}

int _setjmp(jmp_buf buf) {
    return setjmp(buf);
}

char * strcasestr(char * haystack1, char * needle1) {
    char * haystack = strdup(haystack1);
    char * needle = strdup(needle1);
    char * chptr;

    for (chptr = haystack; *chptr; chptr++) *chptr = toupper(*chptr);
    for (chptr = needle; *chptr; chptr++) *chptr = toupper(*chptr);

    chptr = strstr(needle, haystack);
    if (!chptr) return NULL;

    return (chptr - haystack) + haystack1;
}

int _IO_putc(char c, void * f) {
    return putc(c, f);
}

int _IO_getc(void * f) {
    return getc(f);
}

int __xmknod (int __ver, const char * path, unsigned int mode,
		     long long * dev) {
    return mknod(path, mode, *dev);
}


/* this should print the name of the app, but how? probably in a global
   somewhere (like env is) */
void warn(char * format, ...) {
    va_list args;
    int err = errno;

    va_start(args, format);

    fprintf(stderr, "warning: ");
    vfprintf(stderr, format, args);
    fprintf(stderr, ": %s\n", strerror(err));

    va_end(args);

    errno = err;
}

void * __rawmemchr (void* s, int c) {
    while (*(char *)s != c)
	s++;
    return s;
}

char * dcgettext (const char *domainname, const char *msgid, int category) {
    return (char *) msgid;
}

int wcwidth (wchar_t c) {
    return wlite_wcwidth(c);
}

size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, void *ps) {
    return wlite_mbrtowc (pwc, s, n, ps);
}

int iswspace (wchar_t c) {
    return wlite_iswctype((c), wlite_space_);
}

size_t wcrtomb(char *s, wchar_t wc, void *ps) {
    return wlite_wcrtomb (s, wc, ps);
}

/* lie to slang to trick it into using unicode chars for linedrawing */
char *setlocale (int category, const char *locale) {
    if (locale == NULL || *locale == '\0')
	return "en_US.UTF-8";
    return 0;
}

#ifdef GZLIB
void *gzopen(const char *file) {
    return gunzip_open(file);
}

int gzread(void *str, void * buf, int bytes) {
    return gunzip_read(str, buf, bytes);
}

int gzclose(void *str) {
    return gunzip_close(str);
}
#endif