~ubuntu-branches/ubuntu/breezy/photopc/breezy

« back to all changes in this revision

Viewing changes to eph_read.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2005-01-06 18:16:20 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050106181620-wubzm7q4pjidphve
Tags: 3.05-5
Switched from debmake to debhelper and do some cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef LINT
2
 
static char *rcsid="$Id: eph_read.c,v 2.7 1999/08/01 21:36:54 crosser Exp $";
 
2
static char *rcsid="$Id: eph_read.c,v 2.11 2000/07/14 06:35:39 crosser Exp $";
3
3
#endif
4
4
 
5
5
/*
6
 
        Copyright (c) 1997,1998 Eugene G. Crosser
 
6
        Copyright (c) 1997-2000 Eugene G. Crosser
7
7
        Copyright (c) 1998 Bruce D. Lightner (DOS/Windows support)
8
8
 
9
9
        You may distribute and/or use for any purpose modified or unmodified
17
17
 
18
18
/*
19
19
        $Log: eph_read.c,v $
 
20
        Revision 2.11  2000/07/14 06:35:39  crosser
 
21
        reportedly some models return CAN instead of DC1
 
22
        
 
23
        Revision 2.10  2000/05/09 13:20:54  crosser
 
24
        configure read() with alarm() better.
 
25
        Address signed vs. unsigned arguments
 
26
        other cleanups to make most notorious compilers happy
 
27
        
 
28
        Revision 2.9  2000/05/02 22:26:35  crosser
 
29
        A few things incorporated from John Bowman's Nikon specific diffs
 
30
        
 
31
        Revision 2.8  2000/05/02 12:13:32  crosser
 
32
        some better debugging output
 
33
        alarm() based timeouted read (build with "--without-select")
 
34
        
20
35
        Revision 2.7  1999/08/01 21:36:54  crosser
21
36
        Modify source to suit ansi2knr
22
37
        (I hate the style that ansi2knr requires but you don't expect me
59
74
#include <errno.h>
60
75
 
61
76
#include "eph_io.h"
 
77
#include "eph_priv.h"
62
78
 
63
79
#ifdef MSWINDOWS
64
80
#define ERRNO GetLastError()
150
166
# endif
151
167
#endif
152
168
 
 
169
#ifdef USE_ALARMED_READ
 
170
 
 
171
#ifdef HAVE_SIGNAL_H
 
172
#include <signal.h>
 
173
#endif
 
174
#ifdef HAVE_FCNTL_H
 
175
#include <fcntl.h>
 
176
#endif
 
177
 
 
178
static RETSIGTYPE
 
179
alrmhdl(int sig)
 
180
{}
 
181
 
 
182
size_t
 
183
eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc)
 
184
{
 
185
        int ret,timeout_sec;
 
186
        RETSIGTYPE *oldsig;
 
187
 
 
188
        if (length == 0) return 0;
 
189
 
 
190
        if (timeout_usec == 0L) {
 
191
                *rc=1;
 
192
                if (fcntl(iob->fd,F_SETFL,iob->flag|O_NDELAY) == -1)
 
193
                        return (size_t)-1;
 
194
                ret=read(iob->fd,buf,length);
 
195
                if (fcntl(iob->fd,F_SETFL,iob->flag) == -1)
 
196
                        return (size_t)-1;
 
197
                if ((ret == -1) && (errno == EAGAIN)) {
 
198
                        ret=0;
 
199
                        *rc=0;
 
200
                }
 
201
                return ret;
 
202
        }
 
203
 
 
204
#ifdef HAVE_RESTARTABLE_SYSCALLS
 
205
        (void)siginterrupt(SIGALRM,1);
 
206
#endif
 
207
 
 
208
        timeout_sec=timeout_usec/1000000;
 
209
        if (timeout_sec < 2) timeout_sec=2;
 
210
        oldsig=signal(SIGALRM,alrmhdl);
 
211
        alarm((unsigned)timeout_sec);
 
212
        *rc=1;
 
213
        ret=read(iob->fd,buf,length);
 
214
        if ((ret == -1) && (errno == EINTR)) {
 
215
                ret=0;
 
216
                *rc=0;
 
217
        }
 
218
        alarm(0);
 
219
        signal(SIGALRM,oldsig);
 
220
        return ret;
 
221
}
 
222
 
 
223
#else /* USE_ALARMED_READ */
153
224
 
154
225
size_t
155
226
eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc)
171
242
        if ((*rc) == 0) {
172
243
                return 0;
173
244
        }
174
 
        if (((*rc) < 0) || (FD_ISSET(iob->fd,&efds))) return -1;
 
245
        if (((*rc) < 0) || (FD_ISSET(iob->fd,&efds))) return (size_t)-1;
175
246
 
176
247
        return read(iob->fd,buf,length);
177
248
}
178
249
 
 
250
#endif /* USE_ALARMED_READ */
 
251
 
179
252
#elif defined(DOS)
180
253
 
181
254
#include <dos.h>