lkml.org 
[lkml]   [2003]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: O_DIRECT foolish question
On Wed, Feb 12, 2003 at 06:33:23PM -0500, Bruno Diniz de Paula wrote:

> But your code doesn't use O_DIRECT:

Sorry, you need to edit it (see my previous email). A better version
(appended) gives the following results.

cw:3@tapu(cw)$ cp od.c test
cw:3@tapu(cw)$ gcc -Wall od.c
cw:3@tapu(cw)$ ./a.out
read 503 bytes
read 0 bytes

> Let me know whether including O_DIRECT the test worked.

Seems to. I get 0 the 2nd time about, presumably this is EOF but
arguably it should return something else.

--cw

#define _GNU_SOURCE

#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
int h;
int ps;
char *buf;
ssize_t n;

ps = getpagesize();
if (!(buf = valloc(ps)))
return 1;
if ((h = open("test", O_RDONLY|O_DIRECT)) < 0)
return 1;
do {
n = read(h, buf, ps);
if (n == -1) {
perror("read");
break;
}
printf("read %d bytes\n", n);
} while(n);

close(h);

return 0;
}
\
 
 \ /
  Last update: 2005-03-22 13:33    [W:0.040 / U:0.228 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site