HaikuPorts
  • Login
  • Preferences
  • Help/Guide
  • Wiki
  • Timeline
  • Roadmap
  • View Tickets
  • Search
  • Port Log
  • Blog
wiki:FindDirectory

Context Navigation

  • ← Previous Version
  • View Latest Version
  • Next Version →


Version 1 (modified by mmadia, 6 years ago) (diff)

copied content from SandBox

Finding a Directory's Path

When referencing paths, it is best to use Haiku's Find Directory functionality. The system defines numerous key directories in the  os/storage/FindDirectory.h header. In addition to C/C++, a command line utility finddir can be used with the same variable names.

Terminal

export USER_SETTINGS_DIRECTORY=`/bin/finddir B_USER_SETTINGS_DIRECTORY`

To test this, try finddir B_USER_SETTINGS_DIRECTORY

Shell Script

APPS_DIR=`finddir B_APPS_DIRECTORY`
echo ${APPS_DIR}

Makefile

# Assuming the makefile sets

APPS_DIR:=$(shell finddir B_APPS_DIRECTORY)

C

diff -urN tuxpaint-0.9.21/src/fonts.c tuxpaint-0.9.21-haiku/src/fonts.c --- tuxpaint-0.9.21/src/fonts.c 2009-06-06 18:22:00.000000000 +0000 +++ tuxpaint-0.9.21-haiku/src/fonts.c 2009-10-07 07:39:18.000000000 +0000 @@ -67,6 +67,11 @@

?
#include "win32_print.h" #endif

+#ifdef __HAIKU__ +#include <FindDirectory.h> +#include <fs_info.h> +#endif +

?
#ifdef __APPLE__ #include "wrapperdata.h" extern WrapperData macosx;
?
@@ -699,6 +704,14 @@
loadfonts(screen, "/boot/home/config/font/ttffonts"); loadfonts(screen, "/usr/share/fonts"); loadfonts(screen, "/usr/X11R6/lib/X11/fonts");
?

+#elif defined(__HAIKU__) + dev_t volume = dev_for_path("/boot"); + char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; + status_t result; + result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); + loadfonts(screen, buffer); + result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); + loadfonts(screen, buffer);

?
#elif defined(__APPLE__)
loadfonts(screen, "/System/Library/Fonts"); loadfonts(screen, "/Library/Fonts");

C++

// Note: This is untested!

#ifdef __HAIKU__
#include <FindDirectory.h>
#include <fs_info.h>
#endif
        
// ...

BPath dir;
result = find_directory(B_SYSTEM_FONTS_DIRECTORY, &dir);
loadfonts(screen, dir.Path());
result = find_directory(B_COMMON_FONTS_DIRECTORY, &dir);
loadfonts(screen, dir.Path());

Python

#!/bin/env python

import commands

# Creating a utility function
def FindDirectory(aDir):
        result = commands.getoutput('finddir %s' % aDir)
        return result
        

if __name__ == "__main__":
        # Using the utility function ...
        B_APPS_DIRECTORY = FindDirectory('B_APPS_DIRECTORY')
        print 'Using utility function:'
        print B_APPS_DIRECTORY

        # Set a baloney value, to display functionality
        B_APPS_DIRECTORY='Some Text to display the value being set properly'
        print 'After setting a baloney value:'
        print B_APPS_DIRECTORY
 
        # As a one liner ...
        B_APPS_DIRECTORY = commands.getoutput('finddir B_APPS_DIRECTORY')
        print 'Using a one liner:'
        print B_APPS_DIRECTORY

Download in other formats:

  • Plain Text

Trac Powered

Powered by Trac 0.13dev-r10686
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/