Skip to content

Instantly share code, notes, and snippets.

@hiroshiro
Created September 6, 2014 09:38
Show Gist options
  • Save hiroshiro/5ea58be44a674fd7e909 to your computer and use it in GitHub Desktop.
Save hiroshiro/5ea58be44a674fd7e909 to your computer and use it in GitHub Desktop.
関数lseekをテスト。16384バイトシーク
#include "apue.h"
#include <fcntl.h>
char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";
int
main(void)
{
int fd;
if((fd = creat("file.hole", FILE_MODE)) < 0)
err_sys("creat error");
if (write(fd, buf1, 10) != 10)
err_sys("bun1 write error");
/* オフセットはここで 10 */
if (lseek(fd, 16384, SEEK_SET) == -1)
err_sys("lseek error");
/* オフセットはここで 16384 */
if (write(fd, buf2, 10) != 10)
err_sys("buf2 write error");
/* オフセットはここで 16394 */
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment