VirtualBox

Changeset 16688 in vbox for trunk


Ignore:
Timestamp:
Feb 11, 2009 7:10:56 PM (16 years ago)
Author:
vboxsync
Message:

cbinding: Use stat() to check if a file exist (an alternative would be access()). Since this is sample code it need to be commented properly as well as clean (style).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/cbinding/tstLinuxC.c

    r16684 r16688  
    2525#include <string.h>
    2626#include <stdlib.h>
     27#include <sys/stat.h>
    2728#include "cbinding.h"
    2829
     
    301302{
    302303    IVirtualBox *vbox           = NULL;
    303     ISession  *session          = NULL;
    304     PRUint32   revision         = 0;
    305     PRUnichar *versionUtf16     = NULL;
    306     PRUnichar *homefolderUtf16  = NULL;
    307     nsresult rc;     /* Result code of various function (method) calls. */
    308     FILE *fpsetenv;
    309 
    310     if ((fpsetenv = fopen("/opt/VirtualBox/VBoxXPCOMC.so", "r")) != NULL) {
    311         VBoxSetEnv("VBOX_APP_HOME","/opt/VirtualBox/");
    312         fclose (fpsetenv);
    313     }
    314     if ((fpsetenv = fopen("/usr/lib/virtualbox/VBoxXPCOMC.so", "r")) != NULL) {
    315         VBoxSetEnv("VBOX_APP_HOME","/usr/lib/virtualbox/");
    316         fclose (fpsetenv);
     304    ISession   *session          = NULL;
     305    PRUint32    revision         = 0;
     306    PRUnichar  *versionUtf16     = NULL;
     307    PRUnichar  *homefolderUtf16  = NULL;
     308    struct stat stIgnored;
     309    nsresult    rc;     /* Result code of various function (method) calls. */
     310
     311    /*
     312     * Guess where VirtualBox is installed not mentioned in the environment.
     313     * (This will be moved to VBoxComInitialize later.)
     314     */
     315
     316    if (!VBoxGetEnv("VBOX_APP_HOME"))
     317    {
     318        if (stat("/opt/VirtualBox/VBoxXPCOMC.so", &stIgnored) == 0)
     319        {
     320            VBoxSetEnv("VBOX_APP_HOME","/opt/VirtualBox/");
     321        }
     322        if (stat("/usr/lib/virtualbox/VBoxXPCOMC.so", &stIgnored) == 0)
     323        {
     324            VBoxSetEnv("VBOX_APP_HOME","/usr/lib/virtualbox/");
     325        }
    317326    }
    318327
     
    335344    if (session == NULL)
    336345    {
    337         fprintf (stderr, "%s: FATAL: could not get session handle\n", argv[0]);
     346        fprintf(stderr, "%s: FATAL: could not get session handle\n", argv[0]);
    338347        return EXIT_FAILURE;
    339348    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette