737c974400
- Split tests/ (libc feature tests) and examples/ (real apps); shared
app.mk in repo root, was examples/example.mk
- libc/io/* split into libc/{conio,env,errno,file,mouse,string,sys,
time,video}/ — clearer module boundaries
- New examples/mdview/: markdown viewer (Phases 1-5 + light nested
lists). Headers (H1-H4), HR, ulist/olist/quote with nesting via
leading spaces, fenced code blocks, inline emphasis (bold/italic/
underscore/code), wrap/unwrap mode with soft wrap (F2), horizontal
pan (← →) with '>' truncation indicator
- libc additions: scroll() in conio (ESTEX SCROLL), strlwr/strupr,
gets() test
- Makefile updates across tests/ for the new shared app.mk path
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
67 lines
1.8 KiB
C
67 lines
1.8 KiB
C
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
/*
|
|
* Exercises lseek() with offsets that span the 16-bit boundary.
|
|
* big.txt is 102400 bytes (100 KB); every 256-byte block opens with a
|
|
* "[off=NNNNNNN] block #BBBB " label, so any seek aligned to 256 lands
|
|
* on a self-identifying marker.
|
|
*/
|
|
|
|
static void show_marker(int fd, long off)
|
|
{
|
|
long pos = lseek(fd, off, SEEK_SET);
|
|
printf("\nseek %ld -> pos=%ld\n", off, pos);
|
|
|
|
char buf[28];
|
|
int n = read(fd, buf, 27);
|
|
if (n <= 0) {
|
|
printf(" read failed: %d\n", n);
|
|
return;
|
|
}
|
|
buf[n] = 0;
|
|
printf(" bytes: \"%s\"\n", buf);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int fd = open("BIG.TXT", O_RDONLY);
|
|
if (fd < 0) {
|
|
printf("open failed: %d\n", fd);
|
|
(void)getchar();
|
|
return 1;
|
|
}
|
|
|
|
/* Total file size. */
|
|
long size = lseek(fd, 0L, SEEK_END);
|
|
printf("file size = %ld bytes\n", size);
|
|
|
|
/* Seek inside the first 64 KB (high16 = 0). */
|
|
show_marker(fd, 0L);
|
|
show_marker(fd, 256L);
|
|
show_marker(fd, 32768L);
|
|
|
|
/* Right at the 64 KB boundary (offset 0x00010000, high16 = 1). */
|
|
show_marker(fd, 65536L);
|
|
|
|
/* Past 64 KB (high16 still 1, low16 != 0). */
|
|
show_marker(fd, 65536L + 256L);
|
|
show_marker(fd, 81920L);
|
|
|
|
/* Near end of file (size = 102400 = 0x19000, high16 = 1). */
|
|
show_marker(fd, 102400L - 256L);
|
|
|
|
/* SEEK_CUR: from current position, +256. After the previous SEEK_SET
|
|
* to 102144, then read of 27 bytes, pos is 102171. +256 -> 102427,
|
|
* which is past EOF — ESTEX should clamp or error. */
|
|
long after_cur = lseek(fd, 256L, SEEK_CUR);
|
|
printf("\nSEEK_CUR +256 -> pos=%ld (past EOF)\n", after_cur);
|
|
|
|
close(fd);
|
|
puts("");
|
|
puts("Press any key to exit...");
|
|
(void)getchar();
|
|
return 0;
|
|
}
|