1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 4 * Copyright (c) 2017 Fujitsu Ltd. 5 */ 6 7#include <stdio.h> 8#include <string.h> 9#include <errno.h> 10#include "tst_test.h" 11 12static int fd; 13 14static void verify_write(void) 15{ 16 int i, badcount = 0; 17 char buf[BUFSIZ]; 18 19 memset(buf, 'w', BUFSIZ); 20 21 SAFE_LSEEK(fd, 0, SEEK_SET); 22 23 for (i = BUFSIZ; i > 0; i--) { 24 TEST(write(fd, buf, i)); 25 if (TST_RET == -1) { 26 tst_res(TFAIL | TTERRNO, "write failed"); 27 return; 28 } 29 30 if (TST_RET != i) { 31 badcount++; 32 tst_res(TINFO, "write() returned %ld, expected %d", 33 TST_RET, i); 34 } 35 } 36 37 if (badcount != 0) 38 tst_res(TFAIL, "write() failed to return proper count"); 39 else 40 tst_res(TPASS, "write() passed"); 41} 42 43static void setup(void) 44{ 45 fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700); 46} 47 48static void cleanup(void) 49{ 50 if (fd > 0) 51 SAFE_CLOSE(fd); 52} 53 54static struct tst_test test = { 55 .setup = setup, 56 .cleanup = cleanup, 57 .test_all = verify_write, 58 .needs_tmpdir = 1, 59}; 60