Skip to content

Latest commit

 

History

History
executable file
·
153 lines (130 loc) · 4.1 KB

win32_support.h

File metadata and controls

executable file
·
153 lines (130 loc) · 4.1 KB
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Win32 support helper file
This file is only for use with the mpg123 frontend.
win32 support helpers for libmpg123 are in src/libmpg123/compat.h
*/
#ifndef MPG123_WIN32_SUPPORT_H
#define MPG123_WIN32_SUPPORT_H
#include "config.h"
#include "mpg123.h"
#include "httpget.h"
#ifdef HAVE_WINDOWS_H
#define WIN32_LEAN_AND_MEAN 1
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <windows.h>
#include <winnls.h>
#include <shellapi.h>
#include <mmsystem.h>
#if defined (HAVE_WS2TCPIP_H) && !defined (__CYGWIN__)
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#if defined (WANT_WIN32_SOCKETS) /*conflict with gethostname and select in select.h and unistd.h */
/*
Note: Do not treat return values as valid file/socket handles, they only indicate success/failure.
file descriptors are ignored, only the local ws.local_socket is used for storing socket handle,
so the socket handle is always associated with the last call to win32_net_http_open
*/
/**
* Opens an http URL
* @param[in] url URL to open
* @param[out] hd http data info
* @return -1 for failure, 1 for success
*/
int win32_net_http_open(char* url, struct httpdata *hd);
/**
* Reads from network socket
* @param[in] filedes Value is ignored, last open connection is used.
* @param[out] buf buffer to store data.
* @param[in] nbyte bytes to read.
* @return bytes read successfully from socket
*/
ssize_t win32_net_read (int fildes, void *buf, size_t nbyte);
/**
* Writes to network socket
* @param[in] filedes Value is ignored, last open connection is used.
* @param[in] buf buffer to read data from.
* @param[in] nbyte bytes to write.
* @return bytes written successfully to socket
*/
ssize_t win32_net_write (int fildes, const void *buf, size_t nbyte);
/**
* Similar to fgets - get a string from a stream
* @param[out] s buffer to Write to
* @param[in] n bytes of data to read.
* @param[in] stream ignored for compatiblity, last open connection is used.
* @return pointer to s if successful, NULL if failture
*/
char *win32_net_fgets(char *s, int n, int stream);
/**
* Initialize Winsock 2.2.
*/
void win32_net_init (void);
/**
* Shutdown all win32 sockets.
*/
void win32_net_deinit (void);
/**
* Close last open socket.
* @param[in] sock value is ignored.
*/
void win32_net_close (int sock);
/**
* Set reader callback for mpg123_open_fd
* @param[in] fr pointer to a mpg123_handle struct.
*/
void win32_net_replace (mpg123_handle *fr);
#endif
#ifdef WANT_WIN32_UNICODE
/**
* Put the windows command line into argv / argc, encoded in UTF-8.
* You are supposed to free up resources by calling win32_cmdline_free with the values you got from this one.
* @return 0 on success, -1 on error */
int win32_cmdline_utf8(int * argc, char *** argv);
/**
* Free up cmdline memory (the argv itself, theoretically hidden resources, too).
*/
void win32_cmdline_free(int argc, char **argv);
#endif /* WIN32_WANT_UNICODE */
/**
* Set process priority
* @param arg -2: Idle, -1, bellow normal, 0, normal (ignored), 1 above normal, 2 highest, 3 realtime
*/
void win32_set_priority (const int arg);
#ifdef WANT_WIN32_FIFO
/**
* win32_fifo_mkfifo
* Creates a named pipe of path.
* Should be closed with win32_fifo_close.
* @param[in] path Path of pipe, should be in form of "\\.\pipe\pipename".
* @return -1 on failure, 0 otherwise.
* @see win32_fifo_close
*/
int win32_fifo_mkfifo(const char *path);
/**
*win32_fifo_close
* Closes previously open pipe
*/
void win32_fifo_close(void);
/**
* win32_fifo_read_peek
* Checks how many bytes in fifo is pending read operation
* Only the tv_sec member in timeval is evaluated! No microsecond precision.
* @param[in] tv contains information on block duration
* @return bytes available
*/
DWORD win32_fifo_read_peek(struct timeval *tv);
/***
* win32_fifo_read
* Read up to nbyte of data from open pipe into buf
* @param[in] buf Pointer to buffer.
* @param[in] nbyte Number of bytes to read up to.
* @return Number of bytes actually read.
*/
ssize_t win32_fifo_read(void *buf, size_t nbyte);
#endif /* #ifdef WANT_WIN32_FIFO */
#endif /* HAVE_WINDOWS_H */
#endif /* MPG123_WIN32_SUPPORT_H */