Commit a66fed62 authored by Luca Weiss's avatar Luca Weiss Committed by Oliver Smith

Format **/*.c with clang-format (!465)

[ci:skip-build]: already built successfully in CI
[ci:skip-vercheck]
parent 90e2cc7e
Pipeline #68205365 failed with stages
in 2 minutes and 1 second
......@@ -63,4 +63,4 @@ package() {
done
done
}
sha512sums="f8366add6ba2ac6d9f8af89f389c69914009b12b21e6608121a78d1cd9afe287e24eafb0c21d80d096df9eee9a23cc2e6a5408f6355e27be05203186a0bf9814 crossdirect.c"
sha512sums="20b963322820de038257304c1eefa85767b78e242eda7459f06d70a1cfae5540a445aa7d5587024bf4d88a4bee28120ef9f5c2d24a648e71b542b9618318deb2 crossdirect.c"
// HOSTSPEC is defined at compile time, see APKBUILD
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <libgen.h>
#include <errno.h>
#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define NATIVE_BIN_DIR "/native/usr/lib/ccache/bin"
void exit_userfriendly() {
void exit_userfriendly()
{
fprintf(stderr, "Please report this at: https://gitlab.com/postmarketOS/pmaports/issues\n");
fprintf(stderr, "As a workaround, you can compile without crossdirect.\n");
fprintf(stderr, "See 'pmbootstrap -h' for related options.\n");
exit(1);
}
bool argv_has_arg(int argc, char** argv, const char* arg) {
bool argv_has_arg(int argc, char **argv, const char *arg)
{
size_t arg_len = strlen(arg);
for (int i=1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
if (strlen(argv[i]) < arg_len)
continue;
......@@ -31,13 +33,14 @@ bool argv_has_arg(int argc, char** argv, const char* arg) {
return false;
}
int main(int argc, char** argv) {
int main(int argc, char **argv)
{
// we have a max of four extra args ("-target", "HOSTSPEC", "--sysroot=/", "-Wl,-rpath-link=/lib:/usr/lib"), plus one ending null
char* newargv[argc + 5];
char* executableName = basename(argv[0]);
char *newargv[argc + 5];
char *executableName = basename(argv[0]);
char newExecutable[PATH_MAX];
bool isClang = (strcmp(executableName, "clang") == 0 || strcmp(executableName, "clang++") == 0);
bool startsWithHostSpec = (strncmp(HOSTSPEC, executableName, sizeof(HOSTSPEC) -1) == 0);
bool startsWithHostSpec = (strncmp(HOSTSPEC, executableName, sizeof(HOSTSPEC) - 1) == 0);
// linker is involved: just use qemu binary (to avoid broken cross-ld, pmaports#227)
if (!argv_has_arg(argc, argv, "-c")) {
......@@ -50,12 +53,12 @@ int main(int argc, char** argv) {
}
if (isClang || startsWithHostSpec) {
snprintf(newExecutable, sizeof(newExecutable), NATIVE_BIN_DIR "/%s", executableName);
snprintf(newExecutable, sizeof(newExecutable), NATIVE_BIN_DIR "/%s", executableName);
} else {
snprintf(newExecutable, sizeof(newExecutable), NATIVE_BIN_DIR "/" HOSTSPEC "-%s", executableName);
snprintf(newExecutable, sizeof(newExecutable), NATIVE_BIN_DIR "/" HOSTSPEC "-%s", executableName);
}
char** newArgsPtr = newargv;
char **newArgsPtr = newargv;
*newArgsPtr++ = newExecutable;
if (isClang) {
*newArgsPtr++ = "-target";
......@@ -63,16 +66,16 @@ int main(int argc, char** argv) {
}
*newArgsPtr++ = "--sysroot=/";
memcpy(newArgsPtr, argv + 1, sizeof(char*)*(argc - 1));
memcpy(newArgsPtr, argv + 1, sizeof(char *) * (argc - 1));
newArgsPtr += (argc - 1);
*newArgsPtr = NULL;
// new arguments prepared; now setup environmental vars
char* env[] = {"LD_PRELOAD=",
char *env[] = { "LD_PRELOAD=",
"LD_LIBRARY_PATH=/native/lib:/native/usr/lib",
"CCACHE_PATH=/native/usr/bin",
NULL};
char* ldPreload = getenv("LD_PRELOAD");
NULL };
char *ldPreload = getenv("LD_PRELOAD");
if (ldPreload) {
if (strcmp(ldPreload, "/usr/lib/libfakeroot.so") == 0) {
env[0] = "LD_PRELOAD=/native/usr/lib/libfakeroot.so";
......
......@@ -22,4 +22,4 @@ package() {
"${pkgdir}/usr/sbin/fbdebug"
}
sha512sums="c75972faa180567fccabf63723693a3dfe6240f891eee9d580a1bfce2a8858cb746a4cc9704990f90abe94f3759ac47ca5203f1309e525d880a8663235a7e209 fbdebug.c"
sha512sums="c2b99024d4d3f1a47b5dcdff175b611d3c16175553076badafdaf9628ed85f95d955d09366a25d34a0f63a00c58bbdd063f6f531f60254b20420d47d7e3adb2f fbdebug.c"
This diff is collapsed.
......@@ -27,5 +27,5 @@ package() {
install -D -m755 "$srcdir"/hello-world \
"$pkgdir"/usr/bin/hello-world
}
sha512sums="d5ad91600d9be3e53be4cb6e5846b0757786c947b2c0d10f612f67262fc91c148e8d73621623e259ca9dcd5e2c8ec7069cebec44165e203ea8c0133669d3382d main.c
sha512sums="62385af6a68cd4e0c03b15992bb9f1d20b8d6c8a33724ca2d28629a139e95016d0502257f8a3a8be53eef30e11b3e372a2469cb1989dbd387ebea4464a9273ee main.c
80c32948d3254f5e4f9084d73754824e7d7d7d117770b041a1a13baf056773de265153fe518cc3e735db55b638411aa6fbd0e17b5b674dfc89e69a9391fbd3bb Makefile"
......@@ -2,6 +2,6 @@
int main()
{
printf("hello, world!\n");
return 0;
printf("hello, world!\n");
return 0;
}
......@@ -36,7 +36,7 @@ package() {
}
sha512sums="cd3c4a4bb246d8e2480a9968d3519373ab55126a5b77e975ce53333ed39349194f1afb0dea472d62bdb0ffef1ac93bbadaf3de6362db47ef34c922a1e65c95db build_zip.sh
bb152e86ce420761dd2dca660552131610bb8f39cb7e30c75689aacc7cccddce17a90c998097f1b63b3d68a20f9c2c4823d8d591de156dff827381fe436f3b9d update-binary
38c21dc80aa2530fc06c2960c1318e07d068d403af02133f09ba227106a9b23fb77c3bed904e6135b048846f2733bd5d043235e5ab04598ed9c8fa45cbb15586 disable-warning.c
3e6388602665367990bdf4c068268160c26a80dda7fa43380755f36f1ca8751f4ec8a584a4cce3b37f41d405a992716c4280077d062e186b4027d6b74db84b3c disable-warning.c
2400d18734d08b3d2f5ec2fe4e802cdcacddea851644b47505eff1aac47302699c171b880bca55dd1704cc9cef9ac26082ac89cee802b6bf57ff8cf649373328 pmos_chroot
ef6377f6c062b9a86eb9dfb2aa2c0049fda20f24ec75865a682a50e4655710a18bd7a470deab527e1dd4c273f9ea6a003ec03fc5748d44b1c4fbfc91baa9e358 pmos_install
1b19d507a9142e537d052037a0c0768f064ad9131ac8019b234178dc15c0590dbc549ccf553b7a7d55e977df269d4dc0567b520c890738cb80184fc8235222aa pmos_install_functions
......
......@@ -17,61 +17,61 @@
* along with postmarketos-android-recovery-installer. If not, see <http:www.gnu.org/licenses/>.
*/
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
void close_FDs()
{
unsigned int fd;
struct dirent* ep;
DIR* dp = opendir("/proc/self/fd");
if (dp != NULL) {
// first two entries are . and ..
readdir(dp);
readdir(dp);
while (ep = readdir(dp))
if (sscanf(ep->d_name, "%u", &fd) != EOF)
close(fd);
closedir(dp);
} else {
// try to close all file descriptors by brute-force
// in case the list of open FDs could not be read
// from the procfs
for (fd = 256; fd >= 0; fd--)
close(fd);
}
unsigned int fd;
struct dirent *ep;
DIR *dp = opendir("/proc/self/fd");
if (dp != NULL) {
// first two entries are . and ..
readdir(dp);
readdir(dp);
while (ep = readdir(dp))
if (sscanf(ep->d_name, "%u", &fd) != EOF)
close(fd);
closedir(dp);
} else {
// try to close all file descriptors by brute-force
// in case the list of open FDs could not be read
// from the procfs
for (fd = 256; fd >= 0; fd--)
close(fd);
}
}
// Detach the program from the installation script
void daemonize()
{
pid_t pid;
pid = fork();
if (pid < 0)
exit(1);
if (pid > 0)
exit(0);
if (setsid() < 0)
exit(1);
pid = fork();
if (pid < 0)
exit(1);
if (pid > 0)
exit(0);
umask(0);
chdir("/");
close_FDs();
pid_t pid;
pid = fork();
if (pid < 0)
exit(1);
if (pid > 0)
exit(0);
if (setsid() < 0)
exit(1);
pid = fork();
if (pid < 0)
exit(1);
if (pid > 0)
exit(0);
umask(0);
chdir("/");
close_FDs();
}
// Workaround to disable No OS warning in TWRP
......@@ -88,36 +88,36 @@ void daemonize()
// exited.
int main()
{
daemonize();
daemonize();
int orsin, orsout;
int orsin, orsout;
char command[1024];
char result[512];
char command[1024];
char result[512];
char* commands[] = {"set tw_backup_system_size 999",
"set tw_app_prompt 0"};
char *commands[] = { "set tw_backup_system_size 999",
"set tw_app_prompt 0" };
sleep(4);
sleep(4);
int i;
for (i = 0; i < sizeof(commands)/sizeof(char*); i++) {
if ((orsin = open("/sbin/orsin", O_WRONLY)) == -1)
return 1;
strcpy(command, commands[i]);
write(orsin, command, sizeof(command));
close(orsin);
int i;
for (i = 0; i < sizeof(commands) / sizeof(char *); i++) {
if ((orsin = open("/sbin/orsin", O_WRONLY)) == -1)
return 1;
strcpy(command, commands[i]);
write(orsin, command, sizeof(command));
close(orsin);
// Have to read FIFO file, because it blocks
// the thread processing the command
// (see man 3 mkfifo)
if ((orsout = open("/sbin/orsout", O_RDONLY)) == -1)
return 1;
read(orsout, result, sizeof(result));
close(orsout);
// Have to read FIFO file, because it blocks
// the thread processing the command
// (see man 3 mkfifo)
if ((orsout = open("/sbin/orsout", O_RDONLY)) == -1)
return 1;
read(orsout, result, sizeof(result));
close(orsout);
sleep(3);
}
sleep(3);
}
return 0;
return 0;
}
......@@ -20,5 +20,5 @@ package() {
install -D -m755 "$srcdir"/postmarketos-demos \
"$pkgdir"/usr/bin/postmarketos-demos
}
sha512sums="48db2907ea609bcdafd321aa8659a387ad6325641e01fd83d91be5d320eb6202ab628b73d914658333396e7751e1e283aed413db7e91cce2d782993ef38a7e05 main.c
sha512sums="804bbd4e939bd49a153919a728ee17cf69e98e5d679f106054edf298d775849f8efa4716814ee4b84eaa6bcc2c38d16c2362922978cdd214290dd4968ce645bc main.c
83d8a95e9e1e95dffa8661e547444e83e72e572dcd0c637376f678bbd20a351c4b971a315311edefeb58a4cca14fd3e586fb581a262b2d217e25092459539b98 Makefile"
......@@ -3,56 +3,55 @@
static void onclick(GtkWidget *widget, gpointer command)
{
system((const char*)command);
system((const char *)command);
}
static void activate(GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW (window), "postmarketOS demos");
gtk_window_set_title(GTK_WINDOW(window), "postmarketOS demos");
GtkWidget *button_box = gtk_button_box_new(
GTK_ORIENTATION_VERTICAL);
gtk_container_add(GTK_CONTAINER (window), button_box);
gtk_container_add(GTK_CONTAINER(window), button_box);
const char *programs[] = {
"GTK3 Demo",
"gtk3-demo &",
"gtk3-demo &",
"Firefox (XWayland, needs to be installed)",
"firefox &",
"firefox &",
"weston-presentation-shm (Animation)",
"weston-presentation-shm &",
"weston-presentation-shm &",
"weston-simple-damage (Animation)",
"weston-simple-damage &",
"weston-simple-damage &",
"weston-smoke (Touch)",
"weston-smoke &",
"weston-smoke &",
"weston-editor (Touch)",
"weston-editor &",
"weston-editor &",
"htop (Terminal)",
"weston-terminal -f --shell=/usr/bin/htop &",
"weston-terminal -f --shell=/usr/bin/htop &",
"Restart Weston",
"killall weston &",
"killall weston &",
};
for(int i=0;i<(sizeof(programs) / sizeof(const char*));i+=2)
{
for (int i = 0; i < (sizeof(programs) / sizeof(const char *)); i += 2) {
const char *title = programs[i];
const char *command = programs[i+1];
const char *command = programs[i + 1];
GtkWidget *button = gtk_button_new_with_label(title);
gtk_widget_set_size_request(button, 200, 70);
g_signal_connect(button, "clicked", G_CALLBACK (onclick),
(void*)command);
g_signal_connect(button, "clicked", G_CALLBACK(onclick),
(void *)command);
gtk_container_add(GTK_CONTAINER(button_box), button);
}
gtk_widget_show_all (window);
gtk_widget_show_all(window);
}
int main (int argc, char **argv)
int main(int argc, char **argv)
{
GtkApplication *app = gtk_application_new("org.postmarketos.demos",
G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK(activate), NULL);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
int status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
......
......@@ -22,4 +22,4 @@ package() {
"${pkgdir}/usr/sbin/reboot-mode"
}
sha512sums="569b6b1cf595e208b8c5731ea8d4334cd5458cbc2a63d5756014f55f04dd89a4b67ec0d0d01d7a1cd935ae13d44e62e3ea6765f626736bc3dc2029b890c20070 reboot-mode.c"
sha512sums="37d282608f30b1b8fa4f7501a8afcaa81902c9dfaee0c4c92ab05028e3a99a69c601dc7fce6ab06582db044b6fd0f5bffabe9d6064af9e670266978d66fe2515 reboot-mode.c"
......@@ -4,14 +4,14 @@
*
* Copyright (C) 2019 Daniele Debernardi <drebrez@gmail.com>
*/
#include <linux/reboot.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/reboot.h>
#include <unistd.h>
void usage(char* appname)
void usage(char *appname)
{
printf("Usage: %s [-h] MODE\n\n", appname);
printf("Reboot the device to the MODE specified (e.g. recovery, bootloader)\n\n");
......@@ -20,19 +20,16 @@ void usage(char* appname)
printf(" -h Show this help message and exit\n");
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
if (argc != 2)
{
if (argc != 2) {
usage(argv[0]);
exit(1);
}
int opt;
while ((opt = getopt(argc, argv, "h")) != -1)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h")) != -1) {
switch (opt) {
case 'h':
default:
usage(argv[0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment