Debian Codegraph @

COSMIC/Sread.c

raw
1 /* Sread.c:
2 * Authors: Charles E. Campbell, Jr.
3 * Terry McRoberts
4 * Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
5 * Permission is hereby granted to use and distribute this code,
6 * with or without modifications, provided that this copyright
7 * notice is copied with it. Like anything else that's free,
8 * Sread.c is provided *as is* and comes with no warranty
9 * of any kind, either expressed or implied. By using this
10 * software, you agree that in no event will the copyright
11 * holder be liable for any damages resulting from the use
12 * of this software.
13 * Date: Aug 22, 2005
14 */
15 #include <stdio.h>
16 #include "sockets.h"
17
18 /* Sread: this function performs a read from a Socket */
19 #ifdef __PROTOTYPE__
20 int Sread(
21 Socket *skt, /* socket handle */
22 void *buf, /* socket character buffer */
23 int buflen) /* max length of buffer */
24 #else
25 int Sread(
26 skt, /* socket handle */
27 buf, /* socket character buffer */
28 buflen) /* max length of buffer */
29 Socket *skt;
30 void *buf;
31 int buflen;
32 #endif
33 {
34 int cnt;
35
36
37 /* sanity check */
38 if(!skt) {
39 return -1;
40 }
41
42 /* read bytes from Socket */
43 cnt = recv(skt->skt,(void *) buf,(unsigned) buflen,0);
44
45 if(cnt > 0) { /* "cnt" bytes received */
46 return cnt;
47 }
48
49 /* error return */
50 ((char *) buf)[0]= '\0';
51 return 0;
52 }
53
54 /* ---------------------------------------------------------------------
55 * vim: ts=4
56 */