File: io_internal.h

package info (click to toggle)
polyml 5.6-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,892 kB
  • ctags: 34,453
  • sloc: cpp: 44,983; ansic: 24,520; asm: 14,850; sh: 11,730; makefile: 551; exp: 484; python: 253; awk: 91; sed: 9
file content (136 lines) | stat: -rw-r--r-- 4,264 bytes parent folder | download
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
/*
    Title:      Data structures shared between basioio.c and network.c.

    Copyright (c) 2000 David C. J. Matthews
    Portions of this code are derived from the original stream io
    package copyright CUTS 1983-2000.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

#ifndef IO_INTERNAL_H
#define IO_INTERNAL_H


#define IO_BIT_OPEN         1
#define IO_BIT_READ         2
#define IO_BIT_WRITE        4
#define IO_BIT_DIR          8 /* Is it a directory entry? */
#define IO_BIT_SOCKET       16 /* Is it a socket? */

#if (defined(_WIN32) && ! defined(__CYGWIN__))

#define IO_BIT_PIPE         128
#define IO_BIT_DEV          256
#define IO_BIT_GUI_CONSOLE  512

#include <winsock2.h>

#else

typedef int SOCKET;
//#include <dirent.h>

#endif

#ifdef HAVE_DIRENT_H
# include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name)
#else
# define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen
# if HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
# if HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
# if HAVE_NDIR_H
# include <ndir.h>
# endif
#endif


typedef struct basic_io_struct
{
    PolyObject *token; /* pointer into ML heap */
    int ioBits; /* Flag bits */
    union {
        int ioDesc; /* File descriptor. */
#if (defined(_WIN32) && ! defined(__CYGWIN__))
        struct {
            HANDLE  hFind; /* FindFirstFile handle */
            WIN32_FIND_DATA lastFind;
            int fFindSucceeded;
        } directory;
        SOCKET sock;
#else
#define sock ioDesc
        DIR *ioDir; /* Directory entry. */
#endif
    } device;
#if (defined(_WIN32) && ! defined(__CYGWIN__))
    HANDLE hAvailable; // Used to signal available data
#endif
} IOSTRUCT, *PIOSTRUCT;

class TaskData;

#define isOpen(s)   ((s)->ioBits & IO_BIT_OPEN)
#define isRead(s)   ((s)->ioBits & IO_BIT_READ)
#define isWrite(s)  ((s)->ioBits & IO_BIT_WRITE)
#define isDirectory(s)  ((s)->ioBits & IO_BIT_DIR)
#define isSocket(s) ((s)->ioBits & IO_BIT_SOCKET)

#if (defined(_WIN32) && ! defined(__CYGWIN__))
// Needed because testing for available input is different depending on the device.
// Console here means our Windows GUI.
#define isPipe(s)       ((s)->ioBits & IO_BIT_PIPE)
#define isDevice(s)     ((s)->ioBits & IO_BIT_DEV)
#define isConsole(s)    ((s)->ioBits & IO_BIT_GUI_CONSOLE)
#endif

extern PIOSTRUCT get_stream(PolyObject *obj);

extern Handle make_stream_entry(TaskData *mdTaskData);
extern void free_stream_entry(POLYUNSIGNED stream_no);
extern void close_stream(PIOSTRUCT str);

extern PIOSTRUCT basic_io_vector;

extern bool emfileFlag;

#if defined(HAVE_STRUCT_STAT_ST_ATIM)
# define STAT_SECS(stat,kind)    (stat)->st_##kind##tim.tv_sec
# define STAT_USECS(stat,kind) (((stat)->st_##kind##tim.tv_nsec + 500) / 1000)
#elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC)
# define STAT_SECS(stat,kind)    (stat)->st_##kind##time
# define STAT_USECS(stat,kind) (((stat)->st_##kind##timensec + 500) / 1000)
#elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
# define STAT_SECS(stat,kind)    (stat)->st_##kind##timespec.tv_sec
# define STAT_USECS(stat,kind) (((stat)->st_##kind##timespec.tv_nsec + 500) / 1000)
#elif defined(HAVE_STRUCT_STAT_ST_ATIME_N)
# define STAT_SECS(stat,kind)    (stat)->st_##kind##time
# define STAT_USECS(stat,kind) (((stat)->st_##kind##time_n + 500) / 1000)
#elif defined(HAVE_STRUCT_STAT_ST_UATIME)
# define STAT_SECS(stat,kind)    (stat)->st_##kind##time
# define STAT_USECS(stat,kind)   (stat)->st_u##kind##time
#else
# define STAT_SECS(stat,kind)    (stat)->st_##kind##time
# define STAT_USECS(stat,kind)   0
#endif

#endif