Project

General

Profile

overload_v2_PLE.c

paul leroy, 02/07/2015 08:58 AM

 
1
#include "stdio.h"
2
#include <sys/types.h>
3
#include <sys/stat.h>
4
#include <fcntl.h>
5
#include <string.h>
6
#include <unistd.h>
7

    
8

    
9
#define DEBUG 1
10

    
11
/* Output format :
12
 *
13
 * "###NEWFD FD FILENAME CS###\n"
14
 * "###DATA FD DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD CS###\n"
15
 * "###CLOSE FD CS###\n"
16
 */
17

    
18
int cs(char * string){
19
   char * ptr = string;
20
   int res=0;
21
   while (*ptr != 0) {
22
       res = (*ptr + res)%10000;
23
       ptr++;
24
   }
25
   return res;
26
}
27
int fdall=0;
28
FILE arrayFILES[NBSOURCEFILES];
29
int opEn(const char *pathname, int flags, ...)
30
{
31
        int fd = fdall;
32
        char mystring[STRINGSIZE];
33
        fdall++;
34
        #ifdef DEBUG
35
        fprintf(stderr,"Call to open %s %d \n",pathname,flags);
36
        #endif
37
        sprintf(mystring,"%04d %s",fd,pathname);
38
        fprintf(stderr,"###NEWFD %s %04d###\n",mystring,cs(mystring));
39
        return fd;
40
}
41

    
42
FILE * foPen(const char *path, const char *mode)
43
{
44
        int fd = fdall;
45
        char mystring[STRINGSIZE];
46
        fdall++;
47
        #ifdef DEBUG
48
        fprintf(stderr,"Call to fopen %s\n",mode);
49
        #endif
50
        sprintf(mystring,"%04d %s",fd,path);
51
        fprintf(stderr,"###NEWFD %s %04d###\n",mystring,cs(mystring));
52
        return &arrayFILES[fd];
53
}
54

    
55
void seTbuf(FILE *stream, char *buf)
56
{
57
        #ifdef DEBUG
58
        fprintf(stderr,"Call to setbuf\n");
59
        #endif
60
}
61
FILE *fdOpen(int fildes, const char *mode)
62
{
63
        #ifdef DEBUG
64
        fprintf(stderr,"Call to fdopen %d %s \n",fildes,mode);
65
        #endif
66
        return &arrayFILES[fildes];
67
}
68

    
69
int clOse(int fd)
70
{
71
        char mystring[STRINGSIZE];
72
        #ifdef DEBUG
73
        fprintf(stderr,"Call to close %d\n",fd);
74
        #endif
75
        sprintf(mystring,"%04d",fd);
76
        fprintf(stderr,"###CLOSE %s %04d###\n",mystring,cs(mystring));
77
        return 0;
78

    
79
}
80

    
81
int fcLose(FILE *fp)
82
{
83
        char mystring[STRINGSIZE];
84
        #ifdef DEBUG
85
        fprintf(stderr,"Call to fclose\n");
86
        #endif
87
        sprintf(mystring,"%04d",((unsigned int)fp-(unsigned int)&arrayFILES)/sizeof(FILE));
88
        fprintf(stderr,"###CLOSE %s %04d###\n",mystring,cs(mystring));
89
        return 0;
90
}
91

    
92
size_t frEad(void *ptr, size_t size, size_t nmemb, FILE *stream)
93
{
94
        #ifdef DEBUG
95
        fprintf(stderr,"Call to fread size = %d\n",size);
96
        #endif
97
        return 0;
98
}
99
int min(int a, int b) {
100
    if(a<b) return a;
101
    return b;
102
}
103
int gendatastring(char * string, int fd, char * ptr, int * size) {
104
    int i;
105
    int offset;
106
    if (*size == 0) {
107
        return 0;
108
    }
109
    sprintf(string,"%04d ",fd);
110
    offset = strlen(string);
111
    for(i=0; i<min(((STRINGSIZE-offset)/2)&0xFFFFFFFE,*size); i++) {
112
        sprintf(&string[offset+i*2],"%02x",(unsigned char)ptr[i]);
113
    }
114
    *size = *size - i;
115
    return i;
116
}
117
size_t fwRite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
118
{
119
        char mystring[STRINGSIZE];
120
        int writtensize;
121
        
122
        #ifdef DEBUG
123
        fprintf(stderr,"Call to fwrite size = %d\n",size);
124
        #endif
125
        while((writtensize = gendatastring(mystring,((unsigned int)stream-(unsigned int)&arrayFILES)/sizeof(FILE),(char *)ptr,&size)) != 0) {
126
            fprintf(stderr,"###DATA %s %04d###\n",mystring,cs(mystring));
127
            ptr = ptr + writtensize;
128
        }
129
        return size;
130
}
131
int fsEek(FILE *stream, long offset, int whence)
132
{
133
        #ifdef DEBUG
134
        fprintf(stderr,"Call to fseek %d %d \n",offset,whence);
135
        #endif
136
        return 0;
137
}
138
int fcNtl(int fd, int cmd, ...) {
139
    #ifdef DEBUG
140
    fprintf(stderr,"Call to fcntl %d %d\n",fd,cmd);
141
    #endif
142
    return 0;
143
}
144

    
145
int acCess(const char *pathname, int mode)
146
{
147
    #ifdef DEBUG
148
    fprintf(stderr,"Call to access %s %d\n",pathname,mode);
149
    #endif
150
    return 0;
151
}
152

    
153
int mkDir(const char *pathname, mode_t mode)
154
{
155
    #ifdef DEBUG
156
    fprintf(stderr,"Call to mkdir %s %d\n",pathname,mode);
157
    #endif
158
    return 0;
159
}
160
long ftEll(FILE *stream)
161
{
162
    #ifdef DEBUG
163
    fprintf(stderr,"Call to ftell \n");
164
    #endif
165
    return 0;
166
}
167
struct stat st;
168
//int fstat(int fd, struct stat *buf)
169
int fsTat(int fd, struct stat *buf) // modified 25 JUNE 2015 by Paul LEROY
170
{
171
    #ifdef DEBUG
172
    fprintf(stderr,"Call to ftstat %d\n",fd);
173
    #endif
174
    st.st_size = 0;
175
    buf = &st;
176
    return 0;
177
}
178

    
179