Skip to content

Commit

Permalink
added error handling to windows path functions
Browse files Browse the repository at this point in the history
  • Loading branch information
NotLe0n committed Jun 22, 2024
1 parent bed26b0 commit 2e153fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/stdlib/Duden/Pfade.ddp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Binde "Duden/Texte" ein.
Binde "Duden/Zeichen" ein.
Binde "Duden/Fehlerbehandlung" ein.
Binde Betriebssystem und Arbeitsverzeichnis aus "Duden/Laufzeit" ein.

[
Expand Down
8 changes: 6 additions & 2 deletions lib/stdlib/source/path.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#include "ddpmemory.h"
#include "ddptypes.h"
#include "winapi-path.h"
#include <stdbool.h>
#include <string.h>
#include "error.h"

// TODO: Use PathCchCanonicalize
void Windows_Saeubern(ddpstring *ret, ddpstring *path) {
DDP_MIGHT_ERROR;
if (ddp_strlen(path) + 1 >= DDP_MAX_WIN_PATH) {
*ret = DDP_EMPTY_STRING;
return;
}

char cleaned[DDP_MAX_WIN_PATH];
if (!PathCanonicalize(cleaned, path->str)) {
// TODO: Error Handling
ddp_error("Pfad konnte nicht gesäubert werden", false);
*ret = DDP_EMPTY_STRING;
return;
}
Expand All @@ -26,14 +29,15 @@ void Windows_Saeubern(ddpstring *ret, ddpstring *path) {

// TODO: Use PathCchCombine
void Windows_Pfad_Verbinden(ddpstring *ret, ddpstring *a, ddpstring *b) {
DDP_MIGHT_ERROR;
if (ddp_strlen(a) + 1 + ddp_strlen(b) + 1 >= DDP_MAX_WIN_PATH) {
*ret = DDP_EMPTY_STRING;
return;
}

char joined[DDP_MAX_WIN_PATH];
if (!PathCombine(joined, a->str, b->str)) {
// TODO: Error Handling
ddp_error("Pfad konnte nicht verbunden werden", false);
*ret = DDP_EMPTY_STRING;
return;
}
Expand Down

0 comments on commit 2e153fa

Please sign in to comment.