Merge pull request #2587 from colinleroy/rewind-asm-and-fseek-paravirt

Rewrite rewind() in assembly,add lseek() to paravirt
This commit is contained in:
Bob Andrews
2025-01-27 17:18:12 +01:00
committed by GitHub
8 changed files with 195 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/*
!!DESCRIPTION!! fgets test
!!DESCRIPTION!! fread test
!!LICENCE!! Public domain
*/
@@ -51,6 +51,7 @@ int main(int argc,char **argv)
if (r == 0) {
printf("Error: could not start reading.\n");
return EXIT_FAILURE;
}
fwrite(buf, 1, r, stdout);
@@ -63,6 +64,7 @@ int main(int argc,char **argv)
if (!feof(in))
{
printf("We should have EOF!\n");
return EXIT_FAILURE;
}
fclose(in);

73
test/ref/test_fseek.c Normal file
View File

@@ -0,0 +1,73 @@
/*
!!DESCRIPTION!! fseek test
!!LICENCE!! Public domain
*/
#include "common.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
FILE *in;
char bufA[32];
char bufB[32];
#define INFILE "cf.in"
int main(int argc,char **argv)
{
static int r;
in = fopen(INFILE, "rb");
if (in == NULL) {
return EXIT_FAILURE;
}
r = fread(bufA, 1, sizeof(bufA), in);
if (r == 0) {
printf("Error: could not read.\n");
return EXIT_FAILURE;
}
fwrite(bufA, 1, r, stdout);
/* Test SEEK_SET */
fseek(in, 0, SEEK_SET);
r = fread(bufB, 1, sizeof(bufB), in);
if (r == 0) {
printf("Error: could not re-read after SEEK_SET.\n");
return EXIT_FAILURE;
}
fwrite(bufB, 1, r, stdout);
if (memcmp(bufA, bufB, sizeof(bufA))) {
printf("reads differ.\n");
return EXIT_FAILURE;
}
/* Test SEEK_CUR */
fseek(in, 0, SEEK_SET);
fseek(in, 1, SEEK_CUR);
r = fread(bufB, 1, sizeof(bufB), in);
if (r == 0) {
printf("Error: could not re-read after SEEK_CUR.\n");
return EXIT_FAILURE;
}
fwrite(bufB, 1, r, stdout);
if (memcmp(bufA+1, bufB, sizeof(bufA)-1)) {
printf("reads differ.\n");
return EXIT_FAILURE;
}
fclose(in);
return 0;
}

56
test/ref/test_rewind.c Normal file
View File

@@ -0,0 +1,56 @@
/*
!!DESCRIPTION!! rewind test
!!LICENCE!! Public domain
*/
#include "common.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
FILE *in;
char bufA[32];
char bufB[32];
#define INFILE "cf.in"
int main(int argc,char **argv)
{
static int r;
in = fopen(INFILE, "rb");
if (in == NULL) {
return EXIT_FAILURE;
}
r = fread(bufA, 1, sizeof(bufA), in);
if (r == 0) {
printf("Error: could not read.\n");
return EXIT_FAILURE;
}
fwrite(bufA, 1, r, stdout);
rewind(in);
printf("rewind.\n");
r = fread(bufB, 1, sizeof(bufB), in);
if (r == 0) {
printf("Error: could not re-read.\n");
return EXIT_FAILURE;
}
fwrite(bufB, 1, r, stdout);
fclose(in);
if (memcmp(bufA, bufB, sizeof(bufA))) {
printf("reads differ.\n");
return EXIT_FAILURE;
}
return 0;
}