Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vfs/vfs.c

    r6b8e5b7 r089385e8  
    5858static async_sess_t *vfs_sess = NULL;
    5959
     60/* Current (working) directory. */
    6061static FIBRIL_MUTEX_INITIALIZE(cwd_mutex);
    61 
    6262static int cwd_fd = -1;
    6363static char *cwd_path = NULL;
    6464static size_t cwd_size = 0;
     65
     66/* Previous directory. */
     67static FIBRIL_MUTEX_INITIALIZE(pwd_mutex);
     68static int pwd_fd = -1;
     69static char *pwd_path = NULL;
     70static size_t pwd_size = 0;
     71
    6572
    6673/** Start an async exchange on the VFS session.
     
    751758        fibril_mutex_lock(&cwd_mutex);
    752759       
    753         if (cwd_fd >= 0)
    754                 close(cwd_fd);
    755        
    756        
    757         if (cwd_path)
    758                 free(cwd_path);
    759        
     760
     761        fibril_mutex_lock(&pwd_mutex);
     762
     763        if (pwd_fd >= 0)
     764                close(pwd_fd);
     765
     766
     767        if (pwd_path)
     768                free(pwd_path);
     769
     770
     771        pwd_fd = cwd_fd;
     772        pwd_path = cwd_path;
     773        pwd_size = cwd_size;
     774
     775        fibril_mutex_unlock(&pwd_mutex);
     776
    760777        cwd_fd = fd;
    761778        cwd_path = abs;
     
    781798        fibril_mutex_unlock(&cwd_mutex);
    782799       
     800        return buf;
     801}
     802
     803
     804char *getprevwd(char *buf, size_t size)
     805{
     806        if (size == 0)
     807                return NULL;
     808
     809        fibril_mutex_lock(&pwd_mutex);
     810
     811        if ((pwd_size == 0) || (size < pwd_size + 1)) {
     812                fibril_mutex_unlock(&pwd_mutex);
     813                return NULL;
     814        }
     815
     816        str_cpy(buf, size, pwd_path);
     817        fibril_mutex_unlock(&pwd_mutex);
     818
    783819        return buf;
    784820}
Note: See TracChangeset for help on using the changeset viewer.