-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorCheck.c
118 lines (110 loc) · 2.44 KB
/
ErrorCheck.c
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
#include "ErrorCheck.h"
#include <stdio.h>
#include <string.h>
int check_error_so_fopen_args(const char *pathname, const char *mode)
{
if (pathname == NULL || mode == NULL)
{
return THROW_NULL;
}
if (strcmp(pathname, "") == 0)
{
return THROW_NULL;
}
if ((strcmp(mode, "w") != 0) && (strcmp(mode, "r") != 0) && (strcmp(mode, "a") != 0) && (strcmp(mode, "w+") != 0) && (strcmp(mode, "r+") != 0) && (strcmp(mode, "a+") != 0))
{
return THROW_NULL;
}
return MOVEON;
}
int check_error_so_fileno(SO_FILE *stream)
{
if (stream == NULL)
{
printf("Fileno error: NULL STREAM\n");
return THROW_ERR;
}
if (stream->handle < 0)
{
printf("Fileno error: descriptor negativ\n");
return THROW_ERR;
}
return MOVEON;
}
int check_error_so_fflush(SO_FILE *stream)
{
if(stream==NULL)
{
printf("Flush error: NULL STREAM\n");
return THROW_SO_EOF;
}
//FFLUSH ARE SENS DOAR DACA ULTIMA OPERATIE A FOST DE SCRIERE
if(stream->last_operation!=write_op)
{
printf("FFlush nu va face nimic pentru ca ultima operatie nu este de scriere\n");
return THROW_SO_EOF;
}
return MOVEON;
}
int check_error_so_fseek(SO_FILE* stream,long offset,int whence)
{
if(stream==NULL)
{
printf("Fseek:null stream\n");
return THROW_ERR;
}
if((whence!=SEEK_SET)&&(whence!=SEEK_END)&&(whence!=SEEK_CUR))
{
printf("Fseek:whence nu e o valoare valida\n");
return THROW_ERR;
}
if((whence==SEEK_SET) && (offset<0))
{
printf("Fseek:offset negativ pentru SEEK_SET");
return THROW_ERR;
}
return MOVEON;
}
int check_error_so_ftell(SO_FILE* stream)
{
if(stream==NULL)
{
printf("Ftell: argument null\n");
return THROW_ERR;
}
return MOVEON;
}
int check_error_so_feof(SO_FILE* stream)
{
if(stream==NULL)
{
printf("Feof:null argument\n");
return THROW_ERR;
}
return MOVEON;
}
int check_error_so_ferror(SO_FILE* stream)
{
if(stream==NULL)
{
printf("Ferror: null argument\n");
return THROW_ERR;
}
return MOVEON;
}
int check_error_so_fread_fwrite(SO_FILE *stream,size_t size, size_t nmemb)
{
if(stream==NULL)
{
return THROW_SO_EOF;
}
if(size<=0)
{
return THROW_SO_EOF;
}
if(nmemb<=0)
{
return THROW_SO_EOF;
}
return MOVEON;
}