io-util.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <limits.h>
#include <poll.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "io-util.h"
#include "time-util.h"
};
for (;;) {
ssize_t l;
int r;
if (r < 0) {
continue;
return -errno;
} else if (r == 0)
return 0;
if (l < 0) {
continue;
return 0;
return -errno;
} else if (l == 0)
return 0;
}
}
ssize_t n = 0;
/* If called with nbytes == 0, let's call read() at least
* once, to validate the operation */
return -EINVAL;
do {
ssize_t k;
if (k < 0) {
continue;
/* We knowingly ignore any return value here,
* via read() */
continue;
}
return n > 0 ? n : -errno;
}
if (k == 0)
return n;
p += k;
nbytes -= k;
n += k;
} while (nbytes > 0);
return n;
}
ssize_t n;
if (n < 0)
return (int) n;
return -EIO;
return 0;
}
return -EINVAL;
do {
ssize_t k;
if (k < 0) {
continue;
/* We knowingly ignore any return value here,
* via write() */
continue;
}
return -errno;
}
return -EIO;
p += k;
nbytes -= k;
} while (nbytes > 0);
return 0;
}
};
int r;
if (r < 0)
return -errno;
if (r == 0)
return 0;
}
};
int r;
if (r < 0)
return -errno;
if (r == 0)
return 0;
}
size_t n = 0;
while (sz > 0) {
if (*p != 0)
break;
n++;
p++;
sz--;
}
return n;
}
const uint8_t *q, *w, *e;
ssize_t l;
q = w = p;
e = q + sz;
while (q < e) {
size_t n;
n = nul_length(q, e - q);
/* If there are more than the specified run length of
* NUL bytes, or if this is the beginning or the end
* of the buffer, then seek instead of write */
if ((n > run_length) ||
(n > 0 && q == p) ||
(n > 0 && q + n >= e)) {
if (q > w) {
if (l < 0)
return -errno;
if (l != q -w)
return -EIO;
}
return -errno;
q += n;
w = q;
} else if (n > 0)
q += n;
else
q ++;
}
if (q > w) {
if (l < 0)
return -errno;
if (l != q - w)
return -EIO;
}
return q - (const uint8_t*) p;
}