Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <stdbool.h>
  9.  
  10. #define max 256
  11.  
  12.  
  13. #define osErrorFatal(userMsg) osErrorFatalImpl((userMsg), __FILE__, __func__, __LINE__)
  14. #define osAssert(expr, userMsg) \
  15.     do { \
  16.         if (!(expr)) \
  17.             osErrorFatal(userMsg); \
  18.     } while(0)
  19. void osErrorFatalImpl(const char *userMsg, const char *fileName,
  20.                       const char *functionName, const int lineNum);
  21.  
  22. _Bool osispub(const char* path);
  23.  
  24. int main(int argc, char** argv){
  25.   osAssert(argc==2, "Invalid num arg");
  26.  
  27.   printf("%b\n ", osispub(argv[2]));
  28.  
  29.  
  30.   return 0;
  31. }
  32.  
  33. _Bool osispub(const char* fpath){
  34.  
  35.   struct stat finfo;
  36.   osAssert(-1!=stat(fpath, &finfo),"Getting info failed");
  37.   osAssert(S_ISREG(finfo.st_mode) , "File not regular");
  38.   if(finfo.st_mode & S_IROTH  &&  finfo.st_mode & S_IWOTH)
  39.     return true;
  40.   else
  41.     return false;
  42.  
  43.  
  44. }
  45.  
  46. void osErrorFatalImpl(const char *userMsg, const char *fileName,
  47.                       const char *functionName, const int lineNum) {
  48.     perror(userMsg);
  49.     fprintf(stderr, "File: '%s'\nFunction: '%s'\nLine: '%d'\n", fileName, functionName, lineNum);
  50.     exit(EXIT_FAILURE);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement