Last active
June 12, 2021 02:43
-
-
Save doug65536/34039c36f808f68d171ebd6395f97e0f to your computer and use it in GitHub Desktop.
Find first erring seek position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <errno.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdint.h> | |
#include <sys/fcntl.h> | |
#include <inttypes.h> | |
int main() | |
{ | |
int fd = open("test", O_RDWR | O_CREAT, 0644); | |
off_t st = 0; | |
off_t en = INT64_MAX; | |
while (st < en) { | |
off_t md = ((en - st) >> 1) + st; | |
if (lseek(fd, md, SEEK_SET) < 0) | |
en = md; | |
else | |
st = md + 1; | |
} | |
printf("%" PRIx64 "", st); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment