OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Dec 12, 2017 4:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Problems with function to canonicalize a path.
PostPosted: Thu Nov 02, 2017 2:30 pm 
Offline

Joined: Fri Jun 02, 2017 3:01 pm
Posts: 7
EDIT: I already fixed the problem.

Hi, i'm trying to make a in-memory filesystem, everthing was great, until i try to make subdirectories, i debugged a little, and i find the problem, it was in my function to canonicalize the path, that was putting strange symbols in the final string, can some one help me with this?

Here is the function:

Code:
PChar RAMFSJoinPath(PChar src, PChar incr)
{
   if ((!src) && (!incr))      // We need, or src, or incr
   return Null;
   
   PList list = ListNew();
   PChar roff = Null;
   PChar ret = Null;
   UInt32 lsize = 0;
   
   if (incr[0] != '\0' && incr[0] != '\\')      // Copy the src?
   {
      PChar path = StringDump(src);      // YES! So lets make a StringDump() of src, as StringTokenize() change the pointer
      PChar save = Null;
      PChar pch = StringTokenize(path, "\\", &save);
      
      while (pch)
      {
         if (StringCompare(pch, "."))      // Current directory
            ;
         else if (StringCompare(pch, ".."))      // Parent directory
         {
            if (list -> length)      // If the list have any entry,
               MemoryFree((UIntPtr)(ListRemove(list, list -> length - 1)));      // Pop the last one
         }
         else
         {
            PChar str = StringDump(pch);
            ListAdd(list, str);
         }
         
         pch = StringTokenize(Null, "\\", &save);
      }
      
      MemoryFree((UIntPtr)path);
   }
   
   PChar path = StringDump(incr);      // Lets make a StringDump() of incr, as StringTokenize() change the pointer
   PChar save = Null;
   PChar pch = StringTokenize(path, "\\", &save);
   
   while (pch)
   {
      if (StringCompare(pch, "."))      // Current directory
         ;
      else if (StringCompare(pch, ".."))      // Parent directory
      {
         if (list -> length)      // If the list have any entry,
            MemoryFree((UIntPtr)(ListRemove(list, list -> length - 1)));      // Pop the last one
      }
      else
      {
         PChar str = StringDump(pch);
         ListAdd(list, str);
      }
      
      pch = StringTokenize(Null, "\\", &save);
   }
   
   MemoryFree((UIntPtr)path);
   
   if (list -> length == 0)      // We wanna the root directory?
   {
      ListFree(list);      // Yes!
      ret = (PChar)MemoryAlloc(2);
      ret[0] = '\\';
      ret[1] = '\0';
      return ret;
   }
   
   ListForeach(node, list)      // Let's get the size of the final string
      lsize = StringGetLength((PChar)node -> data);
      
   roff = ret = (PChar)MemoryAlloc(lsize + 1);
   
   ListForeach(node, list)      // And copy everthing to it
   {
      StringCopy(roff, "\\");
      roff++;
      StringCopy(roff, (PChar)node -> data);
      roff += StringGetLength((PChar)node -> data);
   }
   
   ListFree(list);
   
   return ret;
}

_________________
Developing CHicago Operating System.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group