Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed Aug 27, 2024
1 parent 5ee322c commit e3933d5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/guess_uri_type.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdlib.h>

#include <string.h>
#include <ctype.h>

#include "filesystem.h"
#include "guess_uri_type.h"

int guess_uri_type(const char* const something) {

int status = 0;

const unsigned char a = something[0];
const unsigned char b = something[1];

if (strncmp(something, "https://", 8) == 0 || strncmp(something, "http://", 7) == 0) {
return GUESS_URI_TYPE_URL;
}

status = (
(a == '.' && (b == '/' || b == '\\')) || (isalpha(a) && b == ':') || (a == '/' || a == '\\')
);

if (!status) {
status = file_exists(something);
}

if (status) {
return GUESS_URI_TYPE_LOCAL_FILE;
}

return GUESS_URI_TYPE_SOMETHING_ELSE;

}
10 changes: 10 additions & 0 deletions src/guess_uri_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#if !defined(GUESS_URI_TYPE_H)
#define GUESS_URI_TYPE_H

#define GUESS_URI_TYPE_URL 0x01
#define GUESS_URI_TYPE_LOCAL_FILE 0x02
#define GUESS_URI_TYPE_SOMETHING_ELSE 0x03

int guess_uri_type(const char* const something);

#endif

0 comments on commit e3933d5

Please sign in to comment.