home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / symlink.c < prev    next >
C/C++ Source or Header  |  1993-05-23  |  1KB  |  69 lines

  1. /* soft link routines */
  2.  
  3. #include <mintbind.h>
  4. #include <errno.h>
  5. #include <string.h>
  6. #include <limits.h>
  7. #include "lib.h"
  8.  
  9. extern int __mint;
  10.  
  11. /*
  12.  * If MiNT 0.9 or later is active, use the kernel routines for these;
  13.  * otherwise, try to choose failure modes that applications will best be
  14.  * able to handle
  15.  */
  16.  
  17. int
  18. symlink(old, new)
  19.     const char *old, *new;
  20. {
  21.     char linkname[PATH_MAX];
  22.     char path[PATH_MAX];
  23.     long r;
  24.  
  25.     if (__mint >= 9) {
  26.         _unx2dos(old, path);
  27.         _unx2dos(new, linkname);
  28.         r = Fsymlink(path, linkname);
  29.         if (r) {
  30.             errno = (int) -r;
  31.             return -1;
  32.         }
  33.         return (int) r;
  34.     }
  35.     errno = EINVAL;
  36.     return -1;
  37. }
  38.  
  39. int
  40. readlink(unxname, buf, siz)
  41.     char *unxname, *buf;
  42.     int siz;
  43. {
  44.     long r;
  45.     size_t l;
  46.     char filename[PATH_MAX];
  47.     char linkto[PATH_MAX+1];
  48.  
  49.     if (__mint < 9) {
  50.         errno = EINVAL;
  51.         return -1;
  52.     }
  53.     _unx2dos(unxname, filename);
  54.     r = Freadlink(PATH_MAX, linkto, filename);
  55.     if (r < 0) {
  56.         errno = (int) -r;
  57.         return -1;
  58.     }
  59.     linkto[PATH_MAX] = 0;
  60.     _dos2unx(linkto, filename);
  61.     l = strlen(filename);
  62.     if (l > siz) {
  63.         errno = ERANGE;
  64.         return -1;
  65.     }
  66.     strncpy(buf, filename, siz);
  67.     return (int) l;
  68. }
  69.