summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/sdlos_os2.c
blob: 2137bace1b4d5adb28c1285c3d5d84d64135e4f6 (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//============================================================
//
//  sdlos_*.c - OS specific low level code
//
//  Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
//  Visit http://mamedev.org for licensing and usage restrictions.
//
//  SDLMAME by Olivier Galibert and R. Belmont
//
//============================================================

// standard sdl header
#include "sdlinc.h"
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/stat.h>

#define INCL_DOS
#include <os2.h>

// MAME headers
#include "osdcore.h"
#include "osdlib.h"

//============================================================
//  osd_get_clipboard_text
//    - used in MESS
//============================================================

char *osd_get_clipboard_text(void)
{
	char *result = NULL;

	return result;
}

//============================================================
//  osd_stat
//============================================================

osd_directory_entry *osd_stat(const char *path)
{
	int err;
	osd_directory_entry *result = NULL;
	struct stat st;

	err = stat(path, &st);

	if( err == -1) return NULL;

	// create an osd_directory_entry; be sure to make sure that the caller can
	// free all resources by just freeing the resulting osd_directory_entry
	result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
	strcpy(((char *) result) + sizeof(*result), path);
	result->name = ((char *) result) + sizeof(*result);
	result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
	result->size = (UINT64)st.st_size;

	return result;
}

//============================================================
//  osd_get_volume_name
//============================================================

const char *osd_get_volume_name(int idx)
{
	static char szDrive[] = "A:\\";

	ULONG ulCurDisk;
	ULONG ulDriveMap;

	DosQueryCurrentDisk(&ulCurDisk, &ulDriveMap);

	szDrive[ 0 ] = 'A';
	while(idx--) {
		do
		{
			ulDriveMap >>= 1;
			szDrive[ 0 ]++;
		} while(ulDriveMap && (ulDriveMap & 1) == 0);
		if (!ulDriveMap) return NULL;
	}

	return szDrive;
}

//============================================================
//  osd_get_full_path
//============================================================

file_error osd_get_full_path(char **dst, const char *path)
{
	*dst = (char *)osd_malloc_array(CCHMAXPATH + 1);
	if (*dst == NULL)
		return FILERR_OUT_OF_MEMORY;

	_abspath(*dst, path, CCHMAXPATH + 1);
	return FILERR_NONE;
}