Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- link/link.c: In function ‘main’:
- link/link.c:30:18: error: ‘symlink’ undeclared (first use in this function)
- 30 | fn = symlink;
- | ^~~~~~~
- link/link.c:30:18: note: each undeclared identifier is reported only once for each function it appears in
- make: *** [Makefile;31: link.o] Error 1
- #if defined(__unix__)
- #include <unistd.h>
- #include <dirent.h>
- #include <fcntl.h>
- #include <sys/mman.h>
- #include <sys/random.h>
- #include <sys/stat.h>
- #include <sys/syscall.h>
- #include <sys/sysctl.h>
- #include <sys/sysinfo.h>
- #include <sys/termios.h>
- #include <sys/types.h>
- #include <sys/user.h>
- #elif defined(_WIN32)
- ...
- #endif // OS-Dependent modules
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- ...
- extern int symlink(const char* actualpath, const char* sympath);
- extern int symlink (const char *__from, const char *__to)
- __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))) ;
- extern int link (const char *__from, const char *__to)
- __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))) ;
- #if defined(__unix__)
- #include <unistd.h>
- #include <dirent.h>
- #include <fcntl.h>
- #elif defined(_WIN32)
- // Removed for brevity
- #endif // OS-Dependent modules
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #if !defined(FALSE) || !defined(TRUE)
- enum { FALSE, TRUE };
- #endif // TRUE || FALSE
- // Why does the compiler require this declaration, and only for symlink?
- extern int symlink(const char* actualpath, const char* sympath);
- typedef int (*link_fn)(const char* path, const char* link_path);
- int main(int argc, char *argv[])
- {
- if (argc == 2) {
- if (strcmp(argv[1], "--help") == 0) {
- printf("nUsage: %s <Existing Filename> <New Filename>nn", argv[0]);
- printf("Options: n");
- printf(" -s Create symbolic link instead of a hard linknn");
- return EXIT_SUCCESS;
- }
- }
- if (argc < 3) {
- fprintf(stderr, "Usage: %s <Existing Filename> <New Filename>n", argv[0]);
- return EXIT_FAILURE;
- }
- link_fn fn = link;
- for (size_t i = 1; i < (size_t) argc - 2; ++i) {
- if (strcmp(argv[i], "-s") == 0) {
- fn = symlink;
- }
- }
- const char* existing_path = argv[argc - 2];
- const char* new_path = argv[argc - 1];
- errno = 0;
- const int return_code = fn(existing_path, new_path);
- if (return_code == -1) {
- fprintf(stderr, "[Error] %sn", strerror(errno));
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- CC=gcc
- CFLAGS="-std=c17 -Wall -Wextra -Werror -pedantic"
- gcc version 9.1.0
- Manjaro Linux 18.0.4
- x86-64
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement