~ubuntu-branches/ubuntu/dapper/openssh/dapper

« back to all changes in this revision

Viewing changes to atomicio.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-10-31 07:46:44 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20051031074644-poik7e4un4723tr4
Tags: 1:4.2p1-5ubuntu1
Resynchronise with Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
 
2
 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
2
3
 * Copyright (c) 1995,1999 Theo de Raadt.  All rights reserved.
3
4
 * All rights reserved.
4
5
 *
24
25
 */
25
26
 
26
27
#include "includes.h"
27
 
RCSID("$OpenBSD: atomicio.c,v 1.12 2003/07/31 15:50:16 avsm Exp $");
 
28
RCSID("$OpenBSD: atomicio.c,v 1.13 2005/05/24 17:32:43 avsm Exp $");
28
29
 
29
30
#include "atomicio.h"
30
31
 
31
32
/*
32
33
 * ensure all of data on socket comes through. f==read || f==vwrite
33
34
 */
34
 
ssize_t
 
35
size_t
35
36
atomicio(f, fd, _s, n)
36
37
        ssize_t (*f) (int, void *, size_t);
37
38
        int fd;
39
40
        size_t n;
40
41
{
41
42
        char *s = _s;
42
 
        ssize_t res, pos = 0;
 
43
        size_t pos = 0;
 
44
        ssize_t res;
43
45
 
44
46
        while (n > pos) {
45
47
                res = (f) (fd, s + pos, n - pos);
51
53
                        if (errno == EINTR || errno == EAGAIN)
52
54
#endif
53
55
                                continue;
 
56
                        return 0;
54
57
                case 0:
55
 
                        return (res);
 
58
                        errno = EPIPE;
 
59
                        return pos;
56
60
                default:
57
 
                        pos += res;
 
61
                        pos += (u_int)res;
58
62
                }
59
63
        }
60
64
        return (pos);