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

This commit is contained in:
Matt Mascarenhas 2021-05-31 20:10:04 +01:00
parent cf51ba24e3
commit 61fa4e4808
1 changed files with 5 additions and 20 deletions

View File

@ -23,12 +23,14 @@ typedef struct
version CINERA_APP_VERSION = {
.Major = 0,
.Minor = 8,
.Patch = 13
.Patch = 14
};
#include <stdarg.h> // NOTE(matt): varargs
#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
#undef __USE_XOPEN_EXTENDED
#include <getopt.h> // NOTE(matt): getopts
#include <curl/curl.h>
#include <time.h>
@ -4074,26 +4076,9 @@ SeekBufferForString(buffer *Buffer, char *String,
void
ResolvePath(char **Path)
{
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;
}
char *Result = realpath(*Path, 0);
Free(*Path);
ExtendString0(Path, Wrap0(B.Location));
DeclaimBuffer(&B);
*Path = Result;
}
char *