aboutsummaryrefslogtreecommitdiffstats
path: root/floatmagic.h
blob: c6aabd92412a539ffed7d4a9c03f8051124da635 (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
/*
 * floatmagic.h -- Definitions of isnan and isinf for gawk. 
 */

/* 
 * Copyright (C) 2009 the Free Software Foundation, Inc.
 * 
 * This file is part of GAWK, the GNU implementation of the
 * AWK Programming Language.
 * 
 * GAWK is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GAWK 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/*
 * NOTE: <math.h> MUST be included before this file. Also <config.h>.
 *
 * These definitions are taken from the Autoconf 2.63 manual. Not pretty.
 */

#ifndef HAVE_ISNAN
#ifndef isnan
# define isnan(x) \
    (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
     : sizeof (x) == sizeof (double) ? isnan_d (x) \
     : isnan_f (x))
static inline int isnan_f  (float       x) { return x != x; }
static inline int isnan_d  (double      x) { return x != x; }
static inline int isnan_ld (long double x) { return x != x; }
#endif
#endif

#ifndef HAVE_ISINF
#ifndef isinf
# define isinf(x) \
    (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
     : sizeof (x) == sizeof (double) ? isinf_d (x) \
     : isinf_f (x))
static inline int isinf_f  (float       x) { return isnan (x - x); }
static inline int isinf_d  (double      x) { return isnan (x - x); }
static inline int isinf_ld (long double x) { return isnan (x - x); }
#endif
#endif
="#990000">,C) #define cygwin_socket(A,B,C) ::socket(A,B,C) #define cygwin_listen(A,B) ::listen(A,B) #define cygwin_bind(A,B,C) ::bind(A,B,C) #define cygwin_connect(A,B,C) ::connect(A,B,C) #define debug_printf printf #endif transport_layer_sockets::transport_layer_sockets (int newfd): fd(newfd) { /* This may not be needed in this constructor - it's only used * when creating a connection via bind or connect */ sockdetails.sa_family = AF_UNIX; strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); sdlen = strlen(sockdetails.sa_data) + sizeof(sockdetails.sa_family); }; transport_layer_sockets::transport_layer_sockets (): fd (-1) { sockdetails.sa_family = AF_UNIX; strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); sdlen = strlen(sockdetails.sa_data) + sizeof(sockdetails.sa_family); } void transport_layer_sockets::listen () { /* we want a thread pool based approach. */ if ((fd = cygwin_socket (AF_UNIX, SOCK_STREAM,0)) < 0) printf ("Socket not created error %d\n", errno); if (cygwin_bind(fd, &sockdetails, sdlen)) printf ("Bind doesn't like you. Tsk Tsk. Bind said %d\n", errno); if (cygwin_listen(fd, 5) < 0) printf ("And the OS just isn't listening, all it says is %d\n", errno); } class transport_layer_sockets * transport_layer_sockets::accept () { /* FIXME: check we have listened */ int new_fd; if ((new_fd = cygwin_accept(fd, &sockdetails, &sdlen)) < 0) { printf ("Nup, could' accept. %d\n",errno); return NULL; } transport_layer_sockets *new_conn = new transport_layer_sockets (new_fd); return new_conn; } void transport_layer_sockets::close() { /* FIXME - are we open? */ ::close (fd); } ssize_t transport_layer_sockets::read (char *buf, size_t len) { /* FIXME: are we open? */ return ::read (fd, buf, len); } ssize_t transport_layer_sockets::write (char *buf, size_t len) { /* FIXME: are we open? */ return ::write (fd, buf, len); } bool transport_layer_sockets::connect () { /* are we already connected? */ if (fd != -1) return false; fd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); if (cygwin_connect (fd, &sockdetails, sdlen) < 0) { debug_printf("client connect failure %d\n", errno); ::close (fd); return false; } return true; }