Subversion Repositories Kolibri OS

Rev

Rev 8655 | Rev 8695 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <stdlib.h>
  2. #include <sys/stat.h>
  3. #include "../../kolibri-libc/source/include/ksys.h"
  4. #include <string.h>
  5.  
  6. void *memrchr(const void *m, int c, size_t n)
  7. {
  8.         const unsigned char *s = (const unsigned char*)m;
  9.         c = (unsigned char)c;
  10.         while (n--) if (s[n]==c) return (void *)(s+n);
  11.         return 0;
  12. }
  13.  
  14. void kolibri_set_win_center()
  15. {
  16.     ksys_proc_table_t *info = (ksys_proc_table_t*)malloc(sizeof(ksys_proc_table_t));
  17.     _ksys_process_info(info, -1);
  18.  
  19.     ksys_pos_t screen_size= _ksys_screen_size();
  20.     int new_x = screen_size.x/2-info->winx_size/2;
  21.     int new_y = screen_size.y/2-info->winy_size/2;
  22.     _ksys_change_window(new_x, new_y, -1, -1);
  23.     free(info);
  24. }
  25.  
  26. int mkdir(const char * path, unsigned)
  27. {
  28.    return _ksys_mkdir(path);
  29. }
  30.  
  31. char *dirname (char *path)
  32. {
  33.   static const char dot[] = ".";
  34.   char *last_slash;
  35.   /* Find last '/'.  */
  36.   last_slash = path != NULL ? strrchr (path, '/') : NULL;
  37.   if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
  38.     {
  39.       /* Determine whether all remaining characters are slashes.  */
  40.       char *runp;
  41.       for (runp = last_slash; runp != path; --runp)
  42.         if (runp[-1] != '/')
  43.           break;
  44.       /* The '/' is the last character, we have to look further.  */
  45.       if (runp != path)
  46.         last_slash = (char*)memrchr((void*)path, '/', runp - path);
  47.     }
  48.   if (last_slash != NULL)
  49.     {
  50.       /* Determine whether all remaining characters are slashes.  */
  51.       char *runp;
  52.       for (runp = last_slash; runp != path; --runp)
  53.         if (runp[-1] != '/')
  54.           break;
  55.       /* Terminate the path.  */
  56.       if (runp == path)
  57.         {
  58.           /* The last slash is the first character in the string.  We have to
  59.              return "/".  As a special case we have to return "//" if there
  60.              are exactly two slashes at the beginning of the string.  See
  61.              XBD 4.10 Path Name Resolution for more information.  */
  62.           if (last_slash == path + 1)
  63.             ++last_slash;
  64.           else
  65.             last_slash = path + 1;
  66.         }
  67.       else
  68.         last_slash = runp;
  69.       last_slash[0] = '\0';
  70.     }
  71.   else
  72.     /* This assignment is ill-designed but the XPG specs require to
  73.        return a string containing "." in any case no directory part is
  74.        found and so a static and constant string is required.  */
  75.     path = (char *) dot;
  76.   return path;
  77. }
  78.  
  79. void setcwd(char* path){
  80.     _ksys_setcwd(path);
  81. }
  82.