how much should i handle errors ?
hello since i work a lot with file i thouth adding this block to a project but im not sure if to do so :
Code:
FILE* file_accses(char *path_to_file , char* string)
{
FILE* fp = NULL;
fp = fopen(path_to_file , string);
if (fp == NULL)
{
switch (errno)
{
case EINTR:
{
printf("A signal was caught during fopen(). \n");
break;
}
case EISDIR:
{
printf("The named file is a directory and mode requires write access. \n");
break;
}
case ELOOP:
{
printf(" Too many symbolic links were encountered in resolving path. \n");
break;
}
case ENAMETOOLONG:
{
printf("Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}. \n");
printf("The length of the filename exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}. \n");
break;
}
case ENFILE:
{
printf("The maximum allowable number of files is currently open in the system. \n");
break;
}
case ENOENT:
{
printf("A component of filename does not name an existing file or filename is an empty string. \n");
break;
}
case ENOSPC:
{
printf("The directory or file system that would contain the new file cannot be expanded, the file does not exist, and it was to be created. \n");
break;
}
case ENOTDIR:
{
printf("A component of the path prefix is not a directory. \n");
break;
}
case ENXIO:
{
printf("The named file is a character special or block special file, and the device associated with this special file does not exist. \n");
break;
}
case EOVERFLOW:
{
printf("The named file is a regular file and the size of the file cannot be represented correctly in an object of type off_t. \n");
break;
}
case EROFS:
{
printf("The named file resides on a read-only file system and mode requires write access. \n ");
break;
}
case EINVAL:
{
printf("The value of the mode argument is not valid. \n");
break;
}
case EMFILE:
{
printf("{FOPEN_MAX} streams are currently open in the calling process. \n");
printf("{STREAM_MAX} streams are currently open in the calling process. \n");
break;
}
case ENOMEM:
{
printf("Insufficient storage space is available. \n");
break;
}
case ETXTBSY:
{
printf("The file is a pure proced\n");
break;
}
}
}
return fp;
}
maybe it's too much ?