Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #ifndef _KOLIBRI_H_
  2. #define _KOLIBRI_H_
  3.  
  4. #include <string.h>
  5. #include <stdlib.h>
  6.  
  7. char *dirname (char *path)
  8. {
  9.   static const char dot[] = ".";
  10.   char *last_slash;
  11.   /* Find last '/'.  */
  12.   last_slash = path != NULL ? strrchr (path, '/') : NULL;
  13.   if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
  14.     {
  15.       /* Determine whether all remaining characters are slashes.  */
  16.       char *runp;
  17.       for (runp = last_slash; runp != path; --runp)
  18.         if (runp[-1] != '/')
  19.           break;
  20.       /* The '/' is the last character, we have to look further.  */
  21.       if (runp != path)
  22.         last_slash = memrchr (path, '/', runp - path);
  23.     }
  24.   if (last_slash != NULL)
  25.     {
  26.       /* Determine whether all remaining characters are slashes.  */
  27.       char *runp;
  28.       for (runp = last_slash; runp != path; --runp)
  29.         if (runp[-1] != '/')
  30.           break;
  31.       /* Terminate the path.  */
  32.       if (runp == path)
  33.         {
  34.           /* The last slash is the first character in the string.  We have to
  35.              return "/".  As a special case we have to return "//" if there
  36.              are exactly two slashes at the beginning of the string.  See
  37.              XBD 4.10 Path Name Resolution for more information.  */
  38.           if (last_slash == path + 1)
  39.             ++last_slash;
  40.           else
  41.             last_slash = path + 1;
  42.         }
  43.       else
  44.         last_slash = runp;
  45.       last_slash[0] = '\0';
  46.     }
  47.   else
  48.     /* This assignment is ill-designed but the XPG specs require to
  49.        return a string containing "." in any case no directory part is
  50.        found and so a static and constant string is required.  */
  51.     path = (char *) dot;
  52.   return path;
  53. }
  54.  
  55.  
  56. void _ksys_setcwd(char* dir){
  57.     __asm__ __volatile__ (
  58.         "int $0x40"
  59.         ::"a"(30), "b"(1), "c"(dir)
  60.     );
  61. };
  62. #endif
  63.