Guest User

Untitled

a guest
Jun 16th, 2019
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. link/link.c: In function ‘main’:
  2. link/link.c:30:18: error: ‘symlink’ undeclared (first use in this function)
  3. 30 | fn = symlink;
  4. | ^~~~~~~
  5. link/link.c:30:18: note: each undeclared identifier is reported only once for each function it appears in
  6. make: *** [Makefile;31: link.o] Error 1
  7.  
  8. #if defined(__unix__)
  9. #include <unistd.h>
  10.  
  11. #include <dirent.h>
  12. #include <fcntl.h>
  13.  
  14. #include <sys/mman.h>
  15. #include <sys/random.h>
  16. #include <sys/stat.h>
  17. #include <sys/syscall.h>
  18. #include <sys/sysctl.h>
  19. #include <sys/sysinfo.h>
  20. #include <sys/termios.h>
  21. #include <sys/types.h>
  22. #include <sys/user.h>
  23. #elif defined(_WIN32)
  24. ...
  25. #endif // OS-Dependent modules
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <errno.h>
  30. ...
  31.  
  32. extern int symlink(const char* actualpath, const char* sympath);
  33.  
  34. extern int symlink (const char *__from, const char *__to)
  35. __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))) ;
  36.  
  37. extern int link (const char *__from, const char *__to)
  38. __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))) ;
  39.  
  40. #if defined(__unix__)
  41. #include <unistd.h>
  42.  
  43. #include <dirent.h>
  44. #include <fcntl.h>
  45. #elif defined(_WIN32)
  46. // Removed for brevity
  47. #endif // OS-Dependent modules
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <errno.h>
  53.  
  54. #if !defined(FALSE) || !defined(TRUE)
  55. enum { FALSE, TRUE };
  56. #endif // TRUE || FALSE
  57.  
  58. // Why does the compiler require this declaration, and only for symlink?
  59. extern int symlink(const char* actualpath, const char* sympath);
  60.  
  61. typedef int (*link_fn)(const char* path, const char* link_path);
  62.  
  63. int main(int argc, char *argv[])
  64. {
  65. if (argc == 2) {
  66. if (strcmp(argv[1], "--help") == 0) {
  67. printf("nUsage: %s <Existing Filename> <New Filename>nn", argv[0]);
  68. printf("Options: n");
  69. printf(" -s Create symbolic link instead of a hard linknn");
  70.  
  71. return EXIT_SUCCESS;
  72. }
  73. }
  74.  
  75. if (argc < 3) {
  76. fprintf(stderr, "Usage: %s <Existing Filename> <New Filename>n", argv[0]);
  77.  
  78. return EXIT_FAILURE;
  79. }
  80.  
  81. link_fn fn = link;
  82.  
  83. for (size_t i = 1; i < (size_t) argc - 2; ++i) {
  84. if (strcmp(argv[i], "-s") == 0) {
  85. fn = symlink;
  86. }
  87. }
  88.  
  89. const char* existing_path = argv[argc - 2];
  90. const char* new_path = argv[argc - 1];
  91.  
  92. errno = 0;
  93.  
  94. const int return_code = fn(existing_path, new_path);
  95.  
  96. if (return_code == -1) {
  97. fprintf(stderr, "[Error] %sn", strerror(errno));
  98.  
  99. return EXIT_FAILURE;
  100. }
  101.  
  102. return EXIT_SUCCESS;
  103. }
  104.  
  105. CC=gcc
  106. CFLAGS="-std=c17 -Wall -Wextra -Werror -pedantic"
  107.  
  108. gcc version 9.1.0
  109. Manjaro Linux 18.0.4
  110. x86-64
RAW Paste Data