efl/src/lib/eina/eina_vpath.h

119 lines
3.7 KiB
C
Raw Normal View History

#ifndef EINA_VPATH_H
#define EINA_VPATH_H
#include "eina_prefix.h"
#ifdef EFL_BETA_API_SUPPORT
/**
* Eina vpath is a path that can be prefixed with a virtual path.
*
* A virtual path can either start with (:XXXXXXXX:) that indicates a virtual
* path with XXXXXXXX as the location, OR a normal path with / or a relative
* path like ./ or ../ or even shell common locators like ~/ or ~username/
*
* The string between (: and :) is used as key to lookup the real value.
* The key has to be set by an interface before, otherwise you will get an
* error.
*
* Sample paths:
*
* ~/myfiles/file.png
* ~bob/dir/file.txt
* /path/to/file.cfg
* ./file/relative/path.txt
* file/relative/path.txt
* (:tmp:)/some-temp-file/file.txt
* (:home:)/myfiles/file.png
*
* (:app.dir:)/bin/app-executable
* (:app.bin:)/app-executable-file
* (:app.lib:)/app-library.so
* (:app.data:)/application/datafile.png
* (:app.locale:)/en_US/LC_MESSAGES/app.mo
* (:app.config:)/application-config.xml
* (:app.local:)/application-data-file.jpg
* (:app.tmp:)/some-temp-file/path/file.txt
*
* (:usr.desktop:)/file-in-users-desktop-directory.txt
* (:usr.documents:)/letter-to-grandma.doc
* (:usr.downloads:)/file-downloaded-here.zip
* (:usr.music:)/fave-song.mp3
* (:usr.pictures:)/a-photo.,jpg
* (:usr.public:)/some-publicly-shared-file
* (:usr.templates:)/some-template-document.txt
* (:usr.videos:)/some-video-file.mp4
* (:usr.data:)/file-in-user-data-dir
* (:usr.config:)/file-in-user-config-dir
* (:usr.cache:)/file-in-user-cache-dir
* (:usr.run:)/file-in-xdg-runtime-dir
* (:usr.tmp:)/some-temp-file/path/file.txt
*
* Commonly mapped to real path (but may vary):
*
* (:tmp:) - /tmp
* (:home:) - ~/
*
* (:app.dir:) - /usr - (assuming app install PREFIX of /usr. may be /usr/local or others too)
* (:app.bin:) - /usr/bin - (almost always PREFIX/bin)
* (:app.lib:) - /usr/lib - (almost always PREFIX/lib)
* (:app.data:) - /usr/share/appname - (almost always PREFIX/share/appname)
* (:app.locale:) - /usr/share/locale - (almost always PREFIX/locale)
* (:app.config:) - ~/.config/appname
* (:app.local:) - ~/.local/share/appname
* (:app.tmp:) - ~/.local/tmp/appname
*
* (:usr.desktop:) - ~/Desktop
* (:usr.documents:) - ~/Documents
* (:usr.downloads:) - ~/Downloads
* (:usr.music:) - ~/Music
* (:usr.pictures:) - ~/Pictures
* (:usr.public:) - ~/Public
* (:usr.templates:) - ~/Templates
* (:usr.videos:) - ~/Videos
* (:usr.data:) - ~/.local/share
* (:usr.config:) - ~/.config
* (:usr.cache:) - ~/.cache
* (:usr.run:) - /var/run/user/1000
* (:usr.tmp:) - ~/.local/tmp
*
* Additional info: https://phab.enlightenment.org/w/eina_vpath/
*
* @since 1.21
*
* @note on Windows, vpath like ~bob/foo is not supported.
*
*/
typedef const char * Eina_Vpath;
/**
* Translate a virtual path into a normal path.
*
* The return string is a string allocated by malloc and should be freed with
* free() when no longer needed.
*
* @param[in] path The path.
* @return NULL if failed, or a full normal string file path that is resolved
*
* @since 1.21
*
*/
eina: Rename EAPI macro to EINA_API in Eina library Summary: Patch from a series of patches to rename EAPI symbols to specific library DSOs. EAPI was designed to be able to pass `__attribute__ ((visibility ("default")))` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as `__atttribute__((visibility("default")))` However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Reviewers: jptiz, lucas, woohyun, vtorri, raster Reviewed By: jptiz, lucas, vtorri Subscribers: ProhtMeyhet, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
EINA_API char *eina_vpath_resolve(Eina_Vpath path);
/**
* Translate a virtual path into a normal path, and print it into str.
*
* @param[out] str the buffer to stuff the characters into
* @param[in] size the size of the buffer
* @param[in] format A snprintf style format string, which will get evaluated after the vpath strings are getting replaced
* @param[in] ... The arguments for the format string
*
* @return the number of characters that are written into str, on a error a value < 0 is returned.
*
* @since 1.21
*
*/
eina: Rename EAPI macro to EINA_API in Eina library Summary: Patch from a series of patches to rename EAPI symbols to specific library DSOs. EAPI was designed to be able to pass `__attribute__ ((visibility ("default")))` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as `__atttribute__((visibility("default")))` However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Reviewers: jptiz, lucas, woohyun, vtorri, raster Reviewed By: jptiz, lucas, vtorri Subscribers: ProhtMeyhet, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
EINA_API int eina_vpath_resolve_snprintf(char *str, size_t size, const char *format, ...);
#endif
#endif