~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/inets/test/httpd_SUITE_data/cgi_echo.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <stdio.h>
 
3
 
 
4
#if defined __WIN32__
 
5
#include <windows.h> 
 
6
#include <fcntl.h>
 
7
#endif
 
8
 
 
9
static int read_exact(char *buffer, int len);
 
10
static int write_exact(char *buffer, int len);
 
11
 
 
12
int main(void)
 
13
{
 
14
    char msg[100];
 
15
    int msg_len;
 
16
#ifdef __WIN32__
 
17
    _setmode(_fileno( stdin),  _O_BINARY);
 
18
    _setmode(_fileno( stdout), _O_BINARY);
 
19
#endif    
 
20
    msg_len = read_exact(msg, 100);
 
21
 
 
22
    write_exact("Content-type: text/plain\r\n\r\n", 28);
 
23
    write_exact(msg, msg_len);
 
24
    exit(EXIT_SUCCESS);
 
25
}
 
26
  
 
27
 
 
28
/* read from stdin */ 
 
29
#ifdef __WIN32__
 
30
static int read_exact(char *buffer, int len)
 
31
{
 
32
    HANDLE standard_input = GetStdHandle(STD_INPUT_HANDLE);
 
33
    
 
34
    unsigned read_result;
 
35
    unsigned sofar = 0;
 
36
    
 
37
    if (!len) { /* Happens for "empty packages */
 
38
        return 0;
 
39
    }
 
40
    for (;;) {
 
41
        if (!ReadFile(standard_input, buffer + sofar,
 
42
                      len - sofar, &read_result, NULL)) {
 
43
            return -1; /* EOF */
 
44
        }
 
45
        if (!read_result) {
 
46
            return -2; /* Interrupted while reading? */
 
47
        }
 
48
        sofar += read_result;
 
49
        if (sofar == len) {
 
50
            return len;
 
51
        }
 
52
    }
 
53
 
54
#else
 
55
static int read_exact(char *buffer, int len) {
 
56
    int i, got = 0;
 
57
    
 
58
    do {
 
59
        if ((i = read(0, buffer + got, len - got)) <= 0)
 
60
            return(i);
 
61
        got += i;
 
62
    } while (got < len);
 
63
    return len;
 
64
   
 
65
}
 
66
#endif
 
67
 
 
68
/* write to stdout */
 
69
#ifdef __WIN32__
 
70
 static int write_exact(char *buffer, int len)
 
71
   {
 
72
     HANDLE standard_output = GetStdHandle(STD_OUTPUT_HANDLE);
 
73
     unsigned written;
 
74
 
 
75
     if (!WriteFile(standard_output, buffer, len, &written, NULL)) {
 
76
       return -1; /* Broken Pipe */
 
77
     }
 
78
     if (written < ((unsigned) len)) {
 
79
       /* This should not happen, standard output is not blocking? */
 
80
       return -2;
 
81
     }
 
82
 
 
83
    return (int) written;
 
84
}
 
85
 
 
86
#else 
 
87
 static int write_exact(char *buffer, int len) {
 
88
   int i, wrote = 0;
 
89
 
 
90
   do {
 
91
     if ((i = write(1, buffer + wrote, len - wrote)) <= 0)
 
92
       return i;
 
93
     wrote += i;
 
94
   } while (wrote < len);
 
95
   return len;
 
96
 }
 
97
#endif