-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated readme and added example programs
- Loading branch information
Showing
3 changed files
with
129 additions
and
19 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <lysys/lysys.h> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
ls_handle file; | ||
ls_handle aio; | ||
int rc; | ||
void *buf; | ||
struct ls_stat st; | ||
|
||
// Open a file for reading asynchronously. | ||
file = ls_open("large.bin", LS_FILE_READ | LS_FLAG_ASYNC, | ||
LS_SHARE_READ, LS_OPEN_EXISTING); | ||
if (!file) | ||
{ | ||
ls_perror("ls_open"); | ||
exit(1); | ||
} | ||
|
||
// Get the size of the file. | ||
rc = ls_fstat(file, &st); | ||
if (rc == -1) | ||
{ | ||
ls_perror("ls_fstat"); | ||
exit(1); | ||
} | ||
|
||
// Allocate a buffer to read the file into. | ||
buf = ls_malloc(st.size); | ||
if (!buf) | ||
{ | ||
ls_perror("ls_malloc"); | ||
exit(1); | ||
} | ||
|
||
// Create an asynchronous I/O handle. | ||
aio = ls_aio_open(file); | ||
if (!aio) | ||
{ | ||
ls_perror("ls_aio_open"); | ||
exit(1); | ||
} | ||
|
||
// Dispatch an asynchronous read operation. | ||
rc = ls_aio_read(aio, 0, buf, st.size); | ||
if (rc == -1) | ||
{ | ||
ls_perror("ls_aio_read"); | ||
exit(1); | ||
} | ||
|
||
// Pretend to do something else. | ||
ls_sleep(1000); | ||
|
||
// Wait for the read to complete. | ||
rc = ls_wait(aio); | ||
if (rc == -1) | ||
{ | ||
ls_perror("ls_wait"); | ||
exit(1); | ||
} | ||
|
||
printf("File read!\n"); | ||
|
||
ls_close(aio); | ||
ls_close(file); | ||
|
||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <lysys/lysys.h> | ||
|
||
static const char string[] = "Hello, world!"; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
char buf[sizeof(string)]; | ||
intptr_t fmt; | ||
int rc; | ||
size_t len; | ||
|
||
// Register a new clipboard format. | ||
fmt = ls_register_clipboard_format("my_format"); | ||
if (fmt == -1) | ||
{ | ||
ls_perror("ls_register_clipboard_format"); | ||
exit(1); | ||
} | ||
|
||
// Set the data in our format. | ||
rc = ls_set_clipboard_data(fmt, string, sizeof(string)); | ||
if (rc == -1) | ||
{ | ||
ls_perror("ls_set_clipboard_data"); | ||
exit(1); | ||
} | ||
|
||
// Get the data back. | ||
len = ls_get_clipboard_data(fmt, buf, sizeof(buf)); | ||
if (len == -1) | ||
{ | ||
ls_perror("ls_get_clipboard_data"); | ||
exit(1); | ||
} | ||
|
||
// Our data was likely overwritten by another application. | ||
if (len == 0) | ||
{ | ||
printf("Data not available in requested format\n"); | ||
return 0; | ||
} | ||
|
||
// Print the data. | ||
printf("Data: %s\n", buf); | ||
|
||
return 0; | ||
} |