Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef PLATFORMSPECIFIC_H_INCLUDED
- #define PLATFORMSPECIFIC_H_INCLUDED
- #include <string.h>
- #ifdef XDG_COMPATIBLE
- static char command[] = "xdg-open";
- #define SYSTEM_FUNCTION
- #elif GNOME_COMPATIBLE
- static char command[] = "gnome-open";
- #define SYSTEM_FUNCTION
- #elif KDE_COMPATIBLE
- static char command[] = "kde-open";
- #define SYSTEM_FUNCTION
- #elif WINDOWS_COMPATIBLE
- static char command[] = "start";
- #define SYSTEM_FUNCTION
- #elif MACOSX_COMPATIBLE
- // Mac Os X compatibility here...
- #endif
- #ifdef SYSTEM_FUNCTION
- int execute(char * command, char * arguments)
- {
- // Definitions:
- int size;
- int result;
- char * tmp;
- // Calculate size of command and arguments
- // + 2 means:
- // The c string style needs one more byte for the null-end.
- // Command and arguments must be separated by one space at least.
- size = strlen(command) + strlen(arguments) + 2;
- // Allocate enough memory to join command and arguments in once.
- tmp = (char*)malloc((size)*sizeof(char));
- // Concatenate command and arguments:
- // First copy command
- strcpy(tmp,command);
- // Concatenate an empty space:
- strcat(tmp," ");
- // Concatenate arguments to command:
- strcat(tmp,arguments);
- // Execute os dependent command:
- result = system(tmp);
- // Free tmp pointer.
- free(tmp);
- return result;
- }
- #endif
- #endif // PLATFORMSPECIFIC_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement