-
Notifications
You must be signed in to change notification settings - Fork 3
/
ddrtry.c
77 lines (71 loc) · 1.66 KB
/
ddrtry.c
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
/*
* Drag & drop sample code.
* Copyright 1992 Atari Corporation
*
* global variables used:
* gl_apid: our AES application id
*
* BUGS/CAVEATS:
* This code is not re-entrant (it uses a static
* variable for the pipe name and for saving the
* SIGPIPE signal handler).
*
* While doing the drag and drop, the SIGPIPE
* signal (write on an empty pipe) is ignored
*/
#include "dragdrop.h"
/*
* ddrtry: get the next header from the drag & drop originator
*
* Input Parameters:
* fd: the pipe handle returned from ddopen()
*
* Output Parameters:
* name: a pointer to the name of the drag & drop item
* (note: this area must be at least DD_NAMEMAX bytes long)
* whichext: a pointer to the 4 byte extension
* size: a pointer to the size of the data
*
* Returns:
* TRUE on success
* FALSE if the originator aborts the transfer
*
* Note: it is the caller's responsibility to actually
* send the DD_OK byte to start the transfer, or to
* send a DD_NAK, DD_EXT, or DD_LEN reply with ddreply().
*/
int dd_rtry(int fd, char *name, char *whichext, long *size)
{
short hdrlen;
int i;
char buf[80];
i = (int)Fread(fd, 2L, &hdrlen);
if (i != 2)
return FALSE;
if (hdrlen < 9) /* this should never happen */
return FALSE;
i = (int)Fread(fd, 4L, whichext);
if (i != 4)
return FALSE;
whichext[4] = 0;
i = (int)Fread(fd, 4L, size);
if (i != 4)
return FALSE;
hdrlen -= 8;
if (hdrlen > DD_NAMEMAX)
i = DD_NAMEMAX;
else
i = hdrlen;
if (Fread(fd, (long)i, name) != i)
return FALSE;
hdrlen -= i;
/* skip any extra header */
while (hdrlen > 80)
{
Fread(fd, 80L, buf);
hdrlen -= 80;
}
if (hdrlen > 0)
Fread(fd, (long)hdrlen, buf);
return TRUE;
}