readlink.c 649 B

1234567891011121314151617181920212223242526272829
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2015 Mike Gerow
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #define MAX_LINK_SIZE 4096
  10. static char usage[] =
  11. "Usage: %s LINK\n";
  12. int main(int argc, char * argv[]) {
  13. if (argc != 2) {
  14. fprintf(stderr, usage, argv[0]);
  15. exit(EXIT_FAILURE);
  16. }
  17. char * name = argv[1];
  18. char buf[MAX_LINK_SIZE];
  19. if (readlink(name, buf, sizeof(buf)) < 0) {
  20. //perror("link");
  21. exit(EXIT_FAILURE);
  22. }
  23. fprintf(stdout, "%s\n", buf);
  24. exit(EXIT_SUCCESS);
  25. }