Files
TheRock/compiler/amd-llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/funopen.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

92 lines
2.2 KiB
C++

// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
// CHECK: READ CALLED; len={{[0-9]*}}
// CHECK-NEXT: READ: test
// CHECK-NEXT: WRITE CALLED: test
// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
// CHECK-NEXT: READ: test
// CHECK-NEXT: WRITE CALLED: test
// CHECK-NEXT: CLOSE CALLED
// CHECK-NEXT: SEEK CALLED; off=100, whence=0
// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
// CHECK-NEXT: READ: test
//
// UNSUPPORTED: darwin, target={{.*(linux|solaris).*}}
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cookie_var;
int f_read(void *cookie, char *buf, int len) {
assert(cookie == &cookie_var);
assert(len >= 6);
printf("READ CALLED; len=%d\n", len);
return strlcpy(buf, "test\n", len);
}
int f_write(void *cookie, const char *buf, int len) {
assert(cookie == &cookie_var);
char *data = strndup(buf, len);
assert(data);
printf("WRITE CALLED: %s\n", data);
free(data);
return len;
}
off_t f_seek(void *cookie, off_t off, int whence) {
assert(cookie == &cookie_var);
assert(whence == SEEK_SET);
printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
return off;
}
int f_close(void *cookie) {
assert(cookie == &cookie_var);
printf("CLOSE CALLED\n");
return 0;
}
int main(void) {
FILE *fp;
char buf[10];
// 1. read-only variant
fp = fropen(&cookie_var, f_read);
assert(fp);
// verify that fileno() does not crash or report nonsense
assert(fileno(fp) == -1);
assert(fgets(buf, sizeof(buf), fp));
printf("READ: %s", buf);
assert(!fclose(fp));
// 2. write-only variant
fp = fwopen(&cookie_var, f_write);
assert(fp);
assert(fileno(fp) == -1);
assert(fputs("test", fp) >= 0);
assert(!fclose(fp));
// 3. read+write+close
fp = funopen(&cookie_var, f_read, f_write, NULL, f_close);
assert(fp);
assert(fileno(fp) == -1);
assert(fgets(buf, sizeof(buf), fp));
printf("READ: %s", buf);
assert(fputs("test", fp) >= 0);
assert(!fclose(fp));
// 4. read+seek
fp = funopen(&cookie_var, f_read, NULL, f_seek, NULL);
assert(fp);
assert(fileno(fp) == -1);
assert(fseek(fp, 100, SEEK_SET) == 0);
assert(fgets(buf, sizeof(buf), fp));
printf("READ: %s", buf);
assert(!fclose(fp));
return 0;
}