aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Filesystem/Filesystem.cpp
blob: 8dce5a373245965c25b39da7e44f93e06478aed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "filesystem.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>  /* defines FILENAME_MAX */

namespace jin
{
	namespace filesystem
	{

		Filesystem* Filesystem::fs = 0;

		Filesystem::Filesystem()
		{
			S = smtnewshared(); 
		}

		Filesystem* Filesystem::get()
		{
			return fs ? fs : (fs = new Filesystem());
		}

		void Filesystem::mount(const char * path)
		{
			int err = smtmount(S, path);
			if (err)
			{
				printf("%s mounted path %s", smterrstr(err), path);
				exit(1); 
			}
		}

		int Filesystem::read(const char* path, Buffer* buffer)
		{
			buffer->data = smtread(S, path, &buffer->size);
			if (buffer->data == 0)
				return 0;
			return 1;
		}

		void* Filesystem::read(const char* path, unsigned int* len)
		{
			return smtread(S, path, len);
		}

		const char* Filesystem::getFull(const char* path)
		{
			return smtfullpath(S, path);
		}

		bool Filesystem::isDir(const char* path)
		{
			return smtisdir(S, path);
		}

		bool Filesystem::isFile(const char* path)
		{
			return smtisreg(S, path); 
		}

		bool Filesystem::exists(const char* path)
		{
			return smtexists(S, path) == 0;
		}

	} // namespace filesystem
} // namespace jin