# [C (clang)], `-DZ=lseek(d,0` + 139 = 152 bytes <!-- language-all: lang-c --> g,j,x,d,s,i,c;f(n){x=0;d=open(n,2);s=Z,2);for(j=2;j--;x++){Z,0);for(i=s;i--;write(d,&x,1));Z,0);for(i=s;i--;read(d,&c,1),c!=x&&x--&&j--);}} [Try it online!][TIO-jnuko05c] [C (clang)]: http://clang.llvm.org/ [TIO-jnuko05c]: https://tio.run/##lY/Ba4MwGMXP7V@ReZCEfpnOa8igq54GG7SDgZciSbSxGsVkLEP81@csPQy6007v4/3e9@AJKprCVPNcQQ0eJFjQIFiJDRk9j5nkXa8MNpAQZnl@kbIbcM0TVlPK/GZDxhziq6u5ZXpxPwftFJYQengghP3hgyrkBYsFg7jjPgw9pWG4NBI2TXMUvR736fueJ3DIsufjIXvj8fXMXlKerLVxqC20wWRcrVf2yzrV4kCJU4e2Tzv0iCLX9lFx77wLCPtNnJSXH22P6O42UeLgvz/T/C3KpqjsTNOcN1ap8zIq/gE "C (clang) – Try It Online" Takes the filename as an argument Ungolfed: <pre><code>#import<fcntl.h> int g,j,x,d,s,i,c; void f(char*n){ 	x=0; 	d=open(n,O_RDWR); 	s=lseek(d,0,SEEK_END); 	j=0; 	for(j=0;j<2;j++){ 		lseek(d,0,SEEK_SET); 		for(i=0;i<s;i++){ 			write(d,&x,1); 		} 		lseek(d,0,SEEK_SET); 		for(i=0;i<s;i++){ 			read(d,&c,1); 			if(c!=x)x--,j--; 		} 		x++; 	} } </code></pre>