Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include <stdint.h>
  2. #include <string.h>
  3.  
  4. void *memrchr(const void *m, int c, size_t n)
  5. {
  6.     const unsigned char *s = (const unsigned char*)m;
  7.     c = (unsigned char)c;
  8.     while (n--) if (s[n]==c) return (void *)(s+n);
  9.     return 0;
  10. }
  11.  
  12. void setcwd(char* path){
  13.     __asm__ __volatile__(
  14.         "int $0x40"
  15.         ::"a"(30), "b"(1), "c"(path)
  16.         :"memory"
  17.     );
  18. }
  19.  
  20. char *dirname(char *path)
  21. {
  22.     static const char dot[] = ".";
  23.     char *last_slash;
  24.     last_slash = path != NULL ? strrchr (path, '/') : NULL;
  25.     if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
  26.     {
  27.       char *runp;
  28.       for (runp = last_slash; runp != path; --runp)
  29.         if (runp[-1] != '/')
  30.           break;
  31.       if (runp != path)
  32.         last_slash = (char*)memrchr((void*)path, '/', runp - path);
  33.     }
  34.     if (last_slash != NULL)
  35.     {
  36.       char *runp;
  37.       for (runp = last_slash; runp != path; --runp)
  38.         if (runp[-1] != '/')
  39.           break;
  40.       if (runp == path)
  41.         {
  42.           if (last_slash == path + 1)
  43.             ++last_slash;
  44.           else
  45.             last_slash = path + 1;
  46.         }
  47.       else
  48.         last_slash = runp;
  49.       last_slash[0] = '\0';
  50.     }
  51.     else
  52.         path = (char *) dot;
  53.     return path;
  54. }
  55.  
  56. #pragma pack(push,1)
  57. typedef struct{
  58.     unsigned            p00;
  59.     union{
  60.         uint64_t        p04;
  61.         struct {
  62.             unsigned    p04dw;
  63.             unsigned    p08dw;
  64.         };
  65.     };
  66.     unsigned            p12;
  67.     union {
  68.         unsigned        p16;
  69.         const char     *new_name;
  70.         void           *bdfe;
  71.         void           *buf16;
  72.         const void     *cbuf16;
  73.     };
  74.     char                p20;
  75.     const char         *p21;
  76. }ksys70_t;
  77.  
  78.  
  79. int kos_mkdir(const char *path, unsigned v)
  80. {
  81.     int status;
  82.     ksys70_t dir_opt;
  83.     dir_opt.p00 = 9;
  84.     dir_opt.p21 = path;
  85.     __asm__ __volatile__(
  86.         "int $0x40"
  87.         :"=a"(status)
  88.         :"a"(70), "b"(&dir_opt)
  89.         :"memory"
  90.     );
  91.     return status;
  92. }