1/* 2 * Copyright (c) 2008 The Hewlett-Packard Development Company 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 23 unchanged lines hidden (view full) --- 32#include <cstdio> 33 34#include "base/atomicio.hh" 35 36ssize_t 37atomic_read(int fd, void *s, size_t n) 38{ 39 char *p = reinterpret_cast<char *>(s); |
40 size_t pos = 0; |
41 42 // Keep reading until we've gotten all of the data. 43 while (n > pos) { 44 ssize_t result = read(fd, p + pos, n - pos); 45 46 // We didn't get any more data, so we should probably punt, 47 // otherwise we'd just keep spinning 48 if (result == 0) --- 12 unchanged lines hidden (view full) --- 61 62 return pos; 63} 64 65ssize_t 66atomic_write(int fd, const void *s, size_t n) 67{ 68 const char *p = reinterpret_cast<const char *>(s); |
69 size_t pos = 0; |
70 71 // Keep writing until we've written all of the data 72 while (n > pos) { 73 ssize_t result = write(fd, p + pos, n - pos); 74 75 // We didn't manage to write anything this time, so we should 76 // probably punt, otherwise we'd just keep spinning 77 if (result == 0) --- 15 unchanged lines hidden --- |