Subversion Repositories Kolibri OS

Rev

Rev 6412 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6412 Rev 6433
Line 3... Line 3...
3
#include 
3
#include 
Line 4... Line 4...
4
 
4
 
5
extern char __argv;
5
extern char __argv;
Line -... Line 6...
-
 
6
extern char __path;
-
 
7
 
-
 
8
int errno = 0;
6
extern char __path;
9
 
Line 7... Line 10...
7
 
10
 
8
const char* getfullpath(const char *path){
11
const char* getfullpath(const char *path){
9
 
12
 
Line 37... Line 40...
37
 
40
 
Line 38... Line 41...
38
        programpath=&__path;
41
        programpath=&__path;
39
 
42
 
40
        if (local_path==1)
43
        if (local_path==1)
41
        {
44
        {
42
                i=0x400;
45
                i=FILENAME_MAX;
43
                //find local path of program
46
                //find local path of program
44
                while(*(programpath+i)!='/')
47
                while(*(programpath+i)!='/')
45
                {
48
                {
46
                        i--;
49
                        i--;
47
                }
50
                }
-
 
51
                localpath_size=i;
-
 
52
                newpath=malloc(FILENAME_MAX);
-
 
53
                if(!newpath)
-
 
54
                {
-
 
55
                    errno = E_NOMEM;
-
 
56
                    return NULL;
48
                localpath_size=i;
57
                }
49
                newpath=malloc(0x400);
58
 
50
                //copy local path to the new path
59
                //copy local path to the new path
51
                for(i=0;i<=localpath_size;i++)
60
                for(i=0;i<=localpath_size;i++)
52
                {
61
                {
Line 59... Line 68...
59
                }
68
                }
60
                return(newpath);
69
                return(newpath);
61
        }
70
        }
Line 62... Line 71...
62
 
71
 
63
       //if we here than path is a relative
72
       //if we here than path is a relative
64
       i=0x400;
73
       i=FILENAME_MAX;
65
       //find local path of program
74
       //find local path of program
66
       while(*(programpath+i)!='/')
75
       while(*(programpath+i)!='/')
67
       {
76
       {
68
                i--;
77
                i--;
Line 73... Line 82...
73
       while((*(path+relpath_pos+i)!='\0') || (*(path+relpath_pos+i)!=0))
82
       while((*(path+relpath_pos+i)!='\0') || (*(path+relpath_pos+i)!=0))
74
       {
83
       {
75
                i++;
84
                i++;
76
       }
85
       }
77
       filename_size=i;
86
       filename_size=i;
78
       newpath=malloc(0x400);
87
       newpath=malloc(FILENAME_MAX);
-
 
88
        if(!newpath)
-
 
89
        {
-
 
90
            errno = E_NOMEM;
-
 
91
            return NULL;
-
 
92
        }
79
        //copy local path to the new path
93
        //copy local path to the new path
80
       for(i=0;i<=localpath_size;i++)
94
       for(i=0;i<=localpath_size;i++)
81
       {
95
       {
82
                *(newpath+i)=*(programpath+i);
96
                *(newpath+i)=*(programpath+i);
83
       }
97
       }
Line 107... Line 121...
107
        {
121
        {
108
                imode=FILE_OPEN_APPEND;
122
                imode=FILE_OPEN_APPEND;
109
                mode++;
123
                mode++;
110
        }else
124
        }else
111
                return 0;
125
                return 0;
-
 
126
        if (*mode=='+')
-
 
127
        {
-
 
128
                imode|=FILE_OPEN_PLUS;
-
 
129
                mode++;
-
 
130
        }
112
        if (*mode=='t')
131
        if (*mode=='t')
113
        {
132
        {
114
                imode|=FILE_OPEN_TEXT;
133
                imode|=FILE_OPEN_TEXT;
115
                mode++;
134
                mode++;
116
        }else if (*mode=='b')
135
        }else if (*mode=='b')
Line 119... Line 138...
119
        {
138
        {
120
                imode|=FILE_OPEN_PLUS;
139
                imode|=FILE_OPEN_PLUS;
121
                mode++;
140
                mode++;
122
        }
141
        }
123
        if (*mode!=0)
142
        if (*mode!=0)
124
                return 0;
143
                return NULL;
125
        res=malloc(sizeof(FILE));
144
        res=malloc(sizeof(FILE));
-
 
145
        if (res)
-
 
146
        {
126
        res->buffer=malloc(256);
147
            res->buffer=malloc(BUFSIZ);
127
        res->buffersize=256;
148
            res->buffersize=BUFSIZ;
128
        res->filesize=0;
149
            res->filesize=0;
129
        res->filepos=0;
150
            res->filepos=0;
130
        res->mode=imode;
151
            res->mode=imode;
131
        res->filename=(char*)getfullpath(filename);
152
            res->filename=(char*)getfullpath(filename);
-
 
153
        }
-
 
154
        if(!res || !res->buffer || !res->filename)
-
 
155
        {
-
 
156
            errno = E_NOMEM;
-
 
157
            return NULL;
-
 
158
        }
Line 132... Line 159...
132
 
159
 
133
	if ((imode==FILE_OPEN_READ) || (imode==FILE_OPEN_APPEND))
160
	if ((imode==FILE_OPEN_READ) || (imode==FILE_OPEN_APPEND))
134
	{
161
	{
135
		res->filesize=_ksys_get_filesize(res->filename);
162
		res->filesize=_ksys_get_filesize(res->filename);