Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug1665511.c
blob68d35a0df08b50cd49bf65dd4877237fcfd0ca3f
1 /*
2 bug1665511.c
3 */
5 #include <testfwk.h>
7 #ifndef __SDCC_pdk14 // Lack of memory - see RFE #605.
9 /* force alignment on sparc machines with gcc compiler */
10 #if defined(PORT_HOST) && defined(__sparc) && defined(__GNUC__)
11 # define LONG_ALIGNED __attribute__ ((aligned (4)))
12 #else
13 # define LONG_ALIGNED
14 #endif
16 typedef union
18 unsigned char bytes[4];
19 long l;
20 } IP_V4, *PIP_V4;
22 typedef union _short_map
24 unsigned char chars[2];
25 short shorts [1];
26 } Short_Map, *PShort_Map;
28 typedef Short_Map Port;
29 typedef Port *PPort;
31 struct sockaddr
33 unsigned char bogus_ptr[3]; ///< Overhead for TNI native interface.
34 unsigned char sin_addr[16] LONG_ALIGNED; ///< IP address. IPv4 address is in sin_addr[12-15] with MSB at sin_addr[12].
35 unsigned char sin_port_high; ///< most significant byte of port number for the socket.
36 unsigned char sin_port_low; ///< least significant byte of port number for the socket.
37 unsigned char sin_family; ///< Ignored by DS80C400 implementation.
40 typedef unsigned int SocketHandle;
42 #define INVALID_HANDLE_VALUE (SocketHandle) -1
44 int accept(SocketHandle handle, struct sockaddr * address, unsigned int size)
46 handle;
47 address;
48 size;
49 return 0x1234;
52 SocketHandle Accept(SocketHandle handle, PIP_V4 ip, PPort port)
54 struct sockaddr address;
55 int RetCode;
57 RetCode = accept(handle, &address, sizeof(address));
58 if (RetCode != INVALID_HANDLE_VALUE)
60 ip->l = ((PIP_V4) &address.sin_addr[12])->l;
61 port->chars[0] = address.sin_port_low;
62 port->chars[1] = address.sin_port_high;
65 return RetCode;
67 #endif
69 void testBug(void)
71 #ifndef __SDCC_pdk14 // Lack of memory.
72 IP_V4 ip = {{1, 2, 3, 4}};
73 Port port = {{5, 6}};
74 ASSERT(Accept(1, &ip, &port) == 0x1234);
75 #endif