summaryrefslogtreecommitdiffstats
path: root/loader/dietstubs.c
blob: 385afecf245495b18c0d2e695897475099f3a585 (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
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <setjmp.h>
#include <ctype.h>
#include <stdarg.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();
}

long long llseek(int fd, long long offest, int whence);

long long lseek64(int fd, long long offset, int whence) {
    return llseek(fd, offset, whence);
}

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;
}

int pwrite(int fd, const void *buf, size_t count, off_t offset) {
    return __pwrite(fd, buf, count, offset);
}