Guest User

Untitled

a guest
Jul 11th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #define MAX_PATH_LEN 200 /* sigh */
  2. typedef char t_path[MAX_PATH_LEN];
  3.  
  4. typedef struct {
  5. t_path next;
  6. t_path remainder;
  7. } t_path_next
  8.  
  9. t_path_next path_walk_into(t_path path) {
  10. t_path_next output;
  11.  
  12. t_path my_next, my_remainder = "/";
  13. strncpy(my_next, path, MAX_PATH_LEN);
  14.  
  15. strsep(&my_next, my_remainder);
  16.  
  17. output.remainder = my_remainder;
  18. output.next = my_next;
  19. return output;
  20. }
  21.  
  22. badp@delta:~/blah$ gcc path.c -Wall
  23. path.c: In function ‘path_walk_into’:
  24. path.c:39: warning: passing argument 1 of ‘strsep’ from incompatible pointer type
  25. /usr/include/string.h:559: note: expected ‘char ** __restrict__’ but argument is of type ‘char (*)[200]’
  26. path.c:41: error: incompatible types when assigning to type ‘t_path’ from type ‘char *’
  27. path.c:42: error: incompatible types when assigning to type ‘t_path’ from type ‘char *’
  28.  
  29. t_path_next path_walk_into(t_path path) {
  30. t_path_next output;
  31. t_path my_path, delim = "/";
  32. char* my_path_ptr = my_path;
  33. strncpy(my_path, path, MAX_PATH_LEN);
  34.  
  35. strsep(&my_path_ptr, delim); //put a on next slash and advance pointer there.
  36.  
  37. if (my_path_ptr == NULL) //no more slashes.
  38. output.remainder[0] = 0;
  39. else
  40. strncpy(output.remainder, my_path_ptr, MAX_PATH_LEN);
  41. strncpy(output.next, my_path, MAX_PATH_LEN);
  42.  
  43. return output;
  44. }
Add Comment
Please, Sign In to add comment