aboutsummaryrefslogtreecommitdiff
path: root/ports/MSVC++/msvc.c
blob: a26c8b022ee68b526a8c8c471f162a11d940914e (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
/*
	msvc: libmpg123 add-ons for MSVC++

	copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
	see COPYING and AUTHORS files in distribution or http://mpg123.org

	originally written by Patrick Dehne (inspired by libmpg123/readers.c)

*/

#include "mpg123lib_intern.h"

#include <tchar.h>
#include <fcntl.h>
#include <io.h>

#include "debug.h"

int mpg123_topen(mpg123_handle *fr, const _TCHAR *path)
{
	int ret;
	int filept; /* descriptor of opened file/stream */

	ret = mpg123_replace_reader(fr, _read, _lseek);
	if(ret != MPG123_OK)
	{
		return ret;
	}

	if((filept = _topen(path, O_RDONLY|O_BINARY)) < 0)
	{
		/* Will not work with unicode path name
		   if(NOQUIET) error2("Cannot open file %s: %s", path, strerror(errno)); */

		if(NOQUIET) error1("Cannot open file: %s", strerror(errno));
		fr->err = MPG123_BAD_FILE;
		return filept; /* error... */
	}

	if(mpg123_open_fd(fr, filept) == MPG123_OK) {
		return MPG123_OK;
	}
	else
	{
		_close(filept);
		return MPG123_ERR;
	}
}

int mpg123_tclose(mpg123_handle *fr)
{
	int ret;

	ret = mpg123_close(fr);
	_close(fr->rdat.filept);

	return ret;
}