Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions library/fcntl/flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,25 @@
#include "stdlib_memory.h"
#endif /* _STDLIB_MEMORY_H */

#include <stdio.h>

int
flock(int fd, int op) {
int ret = -1;
struct flock lock;

if (op != LOCK_SH
&& op != LOCK_EX
&& op != LOCK_UN
&& op != (LOCK_SH|LOCK_NB)
&& op != (LOCK_EX|LOCK_NB)) {
if (op != LOCK_SH && op != LOCK_EX && op != LOCK_UN && op != LOCK_NB) {
__set_errno(EINVAL);
goto out;
}

/* Initialize the flock structure. */
memset(&lock, 0, sizeof(lock));

if (op & LOCK_SH) {
if (op == LOCK_SH) {
lock.l_type = F_RDLCK;
/* Place a shared (read) lock on the file. */
ret = fcntl(fd, F_SETLK, &lock);
}
else if (op & LOCK_EX) {
else if (op == LOCK_EX) {
lock.l_type = F_WRLCK;
/* Place an exclusive (write) lock on the file. */
ret = fcntl(fd, F_SETLK, &lock);
Expand Down
4 changes: 4 additions & 0 deletions library/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include <features.h>

#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#define static_assert _Static_assert
#endif

__BEGIN_DECLS

extern void __assertion_failure(const char *file_name, int line_number, const char *expression);
Expand Down
9 changes: 4 additions & 5 deletions test_programs/dlopen/cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
#include <stdio.h>
#include <dlfcn.h>

void print_name(const char* type)
{
void print_name(const char *type) {
FILE *n = fopen("T:test.txt", "w+");
fprintf(n, "Called\n");
fprintf(n, "Tama is a %s.\n", type);
fclose(n);

void *handle;
void (*func_print_name)(const char*);
void (*func_print_name)(const char *);

handle = dlopen("libdog.so", RTLD_LAZY);
if (handle != NULL) {
*(void**)(&func_print_name) = dlsym(handle, "print_name");
func_print_name("Peppe\n");
*(void **) (&func_print_name) = dlsym(handle, "print_name");
func_print_name("Dog");
dlclose(handle);
}
}
Expand Down
13 changes: 3 additions & 10 deletions test_programs/dlopen/dlopen_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#include <string.h>
#include <dlfcn.h>

int main(int argc, char** argv)
{
int main(int argc, char **argv) {
void *handle;
void (*func_print_name)(const char*);
void (*func_print_name)(const char *);

if (argc != 2) {
fprintf(stderr, "Usage: %s animal_type\n", argv[0]);
Expand All @@ -26,22 +25,16 @@ int main(int argc, char** argv)
fprintf(stderr, "Error: %s\n", dlerror());
return EXIT_FAILURE;
}
#ifdef _CLIB2
if (!__global_clib2)
printf("__global_clib2 is null\n");
#endif

*(void**)(&func_print_name) = dlsym(handle, "print_name");
*(void **) (&func_print_name) = dlsym(handle, "print_name");
if (!func_print_name) {
/* no such symbol */
fprintf(stderr, "Error: %s\n", dlerror());
dlclose(handle);
return EXIT_FAILURE;
}
printf("argv1 = %s\n", argv[1]);

func_print_name(argv[1]);
printf("Closing handle\n");
dlclose(handle);

return EXIT_SUCCESS;
Expand Down
4 changes: 1 addition & 3 deletions test_programs/dlopen/dog.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include <stdio.h>
#include <dlfcn.h>

void print_name(const char* type)
{
void print_name(const char *type) {
printf("Pochi is a %s.\n", type);
}