Revert cinera.c: Make ResolvePath() use realpath()

This reverts commit 61fa4e4808.
This commit is contained in:
Matt Mascarenhas 2021-05-31 20:35:18 +01:00
parent 61fa4e4808
commit 9cdb3b96d9
1 changed files with 20 additions and 5 deletions

View File

@ -23,14 +23,12 @@ typedef struct
version CINERA_APP_VERSION = { version CINERA_APP_VERSION = {
.Major = 0, .Major = 0,
.Minor = 8, .Minor = 8,
.Patch = 14 .Patch = 13
}; };
#include <stdarg.h> // NOTE(matt): varargs #include <stdarg.h> // NOTE(matt): varargs
#include <stdio.h> // NOTE(matt): printf, sprintf, vsprintf, fprintf, perror #include <stdio.h> // NOTE(matt): printf, sprintf, vsprintf, fprintf, perror
#define __USE_XOPEN_EXTENDED // NOTE(matt): realpath()
#include <stdlib.h> // NOTE(matt): calloc, malloc, free #include <stdlib.h> // NOTE(matt): calloc, malloc, free
#undef __USE_XOPEN_EXTENDED
#include <getopt.h> // NOTE(matt): getopts #include <getopt.h> // NOTE(matt): getopts
#include <curl/curl.h> #include <curl/curl.h>
#include <time.h> #include <time.h>
@ -4076,9 +4074,26 @@ SeekBufferForString(buffer *Buffer, char *String,
void void
ResolvePath(char **Path) ResolvePath(char **Path)
{ {
char *Result = realpath(*Path, 0); buffer B;
ClaimBuffer(&B, BID_RESOLVED_PATH, StringLength(*Path) + 1);
CopyStringToBufferNoFormat(&B, Wrap0(*Path));
B.Ptr = B.Location;
while(SeekBufferForString(&B, "/../", C_SEEK_FORWARDS, C_SEEK_END) == RC_SUCCESS)
{
char *NextComponentHead = B.Ptr;
int RemainingChars = StringLength(NextComponentHead);
--B.Ptr;
SeekBufferForString(&B, "/", C_SEEK_BACKWARDS, C_SEEK_BEFORE);
SeekBufferForString(&B, "/", C_SEEK_BACKWARDS, C_SEEK_START);
CopyStringToBufferNoFormat(&B, Wrap0(NextComponentHead));
Clear(B.Ptr, B.Size - (B.Ptr - B.Location));
B.Ptr -= RemainingChars;
}
Free(*Path); Free(*Path);
*Path = Result; ExtendString0(Path, Wrap0(B.Location));
DeclaimBuffer(&B);
} }
char * char *