From owner-freebsd-standards@FreeBSD.ORG Wed Feb 15 14:36:16 2012 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1D00B106566C for ; Wed, 15 Feb 2012 14:36:16 +0000 (UTC) (envelope-from nicolas.bourdaud@gmail.com) Received: from mail-bk0-f54.google.com (mail-bk0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 947758FC15 for ; Wed, 15 Feb 2012 14:36:15 +0000 (UTC) Received: by bkcjg1 with SMTP id jg1so1258651bkc.13 for ; Wed, 15 Feb 2012 06:36:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type:content-transfer-encoding; bh=BSwYS9Pp/T5F/wuhf2XsvxkyQCEloh9CXyxkcV8cPYU=; b=aMQEmhxC4ajULd0vD3vyqJ9K133w2/0Mlt0omc6nk5u1oiSQoalQB+3RAWA9jLz8s5 qvi8IbjKdS3FF+PFYLpaI9TO/p049MbTkiR3KnBhwTrDKYGsKG51r/QIekD2uqxEKTbh MdyGTfhpGOhI/3h5XUm5qYDhcXy1TE4f7DmWg= Received: by 10.205.112.6 with SMTP id eq6mr11983155bkc.16.1329316572982; Wed, 15 Feb 2012 06:36:12 -0800 (PST) Received: from [128.178.22.156] (cnbipc27.epfl.ch. [128.178.22.156]) by mx.google.com with ESMTPS id ut6sm6949599bkb.14.2012.02.15.06.36.12 (version=SSLv3 cipher=OTHER); Wed, 15 Feb 2012 06:36:12 -0800 (PST) Message-ID: <4F3BC2DB.6080703@gmail.com> Date: Wed, 15 Feb 2012 15:36:11 +0100 From: Nicolas Bourdaud User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.26) Gecko/20120131 Lightning/1.0b2 Thunderbird/3.1.18 MIME-Version: 1.0 To: freebsd-standards@freebsd.org X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: write system call violates POSIX standard X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Feb 2012 14:36:16 -0000 [resent since the signature messed my previous message on the mailing list archive] Hi all, When a write() cannot transfer as many bytes as requested (because of a file limit), it fails instead of transferring as many bytes as there is room to write. This is a violation of the POSIX standard: http://pubs.opengroup.org/onlinepubs/007904975/functions/write.html I have provided a small test to verify the problem (fsize-lim.c). I have also created a bug report but I have been advised to post on this mailing list anyway: http://www.freebsd.org/cgi/query-pr.cgi?pr=164793 Best regards Nicolas test file: fsize-lim.c: #include #include #include #include #include #include #include #include #include #include #define TARGETSIZE 80000 #define LIMSIZE 60000 #define PATTSIZE 27 int main(void) { struct rlimit lim; int fd; ssize_t retc; size_t count = 0; const char pattern[PATTSIZE] = "Hello world!"; signal(SIGXFSZ, SIG_IGN); getrlimit(RLIMIT_FSIZE, &lim); lim.rlim_cur = LIMSIZE; setrlimit(RLIMIT_FSIZE, &lim); fd = open("result.txt", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); while (count < TARGETSIZE) { retc = write(fd, pattern, PATTSIZE); if (retc < PATTSIZE && retc > 0) fprintf(stderr, "added %zi bytes instead of %u bytes after %zu bytes\n", retc, PATTSIZE, count); else if (retc < 0) { fprintf(stderr, "failed when adding %u bytes after %zu bytes (error: %s)\n", PATTSIZE, count, strerror(errno)); break; } count += retc; } close(fd); return 0; }