Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap
1 result
Show changes
Commits on Source (50)
......@@ -21,18 +21,14 @@ if(WIN32)
file(GLOB CORE_SRCS
src/*.c
src/etc/*.c
src/win32/*.c
src/rpmalloc/*.c
)
file(GLOB CORE_HEADERS
include/*.h
src/win32/*.h
src/win32/*.h
)
endif()
if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
set(SUBMODULES_NO_BUILD ON)
if(NOT SUBMODULES_NO_BUILD)
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
......@@ -81,7 +77,7 @@ if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
endif()
endif()
add_library(${PROJECT_NAME} STATIC ${CORE_SRCS} ${CORE_UNIX_SRCS})
add_library(${PROJECT_NAME} STATIC ${CORE_SRCS} ${CORE_HEADERS})
#This paths will be used by project-dependent project libraries
target_include_directories(${PROJECT_NAME} INTERFACE include/ src/rpmalloc/)
......@@ -104,6 +100,16 @@ if(DARWIN)
target_link_libraries(${PROJECT_NAME} dap_core_darwin)
endif()
if(ANDROID)
add_subdirectory(src/android)
target_link_libraries(${PROJECT_NAME} dap_core_android)
endif()
if (WIN32)
add_subdirectory(src/win32)
target_link_libraries(${PROJECT_NAME} dap_core_win32)
endif()
if(BUILD_DAP_TESTS)
enable_testing()
add_subdirectory(test)
......
......@@ -22,6 +22,7 @@
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#define _XOPEN_SOURCE 700
#pragma once
......@@ -62,6 +63,12 @@ typedef uint8_t byte_t;
#define ROUNDUP(n,width) (((n) + (width) - 1) & ~(unsigned)((width) - 1))
#endif
#ifdef __cplusplus
#define DAP_CAST_REINT(t,v) reinterpret_cast<t*>(v)
#else
#define DAP_CAST_REINT(t,v) ((t*) v)
#endif
#if DAP_USE_RPMALLOC
#include "rpmalloc.h"
#define DAP_MALLOC(a) rpmalloc(a)
......@@ -70,13 +77,14 @@ typedef uint8_t byte_t;
#define DAP_ALMALLOC(a, b) rpaligned_alloc(a, b)
#define DAP_ALREALLOC(a,b,c) rpaligned_realloc(a, b, c, 0, 0)
#define DAP_ALFREE(a) rpfree(a)
#define DAP_NEW(a) ((a*) rpmalloc(sizeof(a)))
#define DAP_NEW_SIZE(a, b) ((a*) rpmalloc(b))
#define DAP_NEW_Z(a) ((a*) rpcalloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) ((a*) rpcalloc(1,b))
#define DAP_NEW(a) DAP_CAST_REINT(a, rpmalloc(sizeof(a)))
#define DAP_NEW_SIZE(a, b) DAP_CAST_REINT(a, rpmalloc(b))
#define DAP_NEW_Z(a) DAP_CAST_REINT(a, rpcalloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) DAP_CAST_REINT(a, rpcalloc(1,b))
#define DAP_REALLOC(a, b) rprealloc(a,b)
#define DAP_DELETE(a) rpfree(a)
#define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
#define DAP_DUP_SIZE(a,b) ( __typeof(a) ret = memcpy(ret,a,b) )
#else
#define DAP_MALLOC(a) malloc(a)
#define DAP_FREE(a) free(a)
......@@ -84,13 +92,14 @@ typedef uint8_t byte_t;
#define DAP_ALMALLOC(a, b) _dap_aligned_alloc(a, b)
#define DAP_ALREALLOC(a, b) _dap_aligned_realloc(a, b)
#define DAP_ALFREE(a) _dap_aligned_free(a, b)
#define DAP_NEW( a ) ((a*) malloc(sizeof(a)))
#define DAP_NEW_SIZE(a, b) ((a*) malloc(b) )
#define DAP_NEW_Z( a ) ((a*) calloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) ((a*) calloc(1,b))
#define DAP_NEW( a ) DAP_CAST_REINT(a, malloc(sizeof(a)) )
#define DAP_NEW_SIZE(a, b) DAP_CAST_REINT(a, malloc(b) )
#define DAP_NEW_Z( a ) DAP_CAST_REINT(a, calloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) DAP_CAST_REINT(a, calloc(1,b))
#define DAP_REALLOC(a, b) realloc(a,b)
#define DAP_DELETE(a) free(a)
#define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
#define DAP_DUP_SIZE(a,b) ( __typeof(a) memcpy(ret,a,b) )
#endif
DAP_STATIC_INLINE void *_dap_aligned_alloc( uintptr_t alignment, uintptr_t size )
......@@ -319,11 +328,13 @@ DAP_STATIC_INLINE void DAP_AtomicUnlock( dap_spinlock_t *lock )
__sync_lock_release( lock );
}
extern char s_sys_dir_path[MAX_PATH];
extern unsigned int l_sys_dir_path_len;
extern char *g_sys_dir_path;
//int dap_common_init( const char * a_log_file );
int dap_common_init( const char *console_title, const char *a_log_file );
int wdap_common_init( const char *console_title, const wchar_t *a_wlog_file);
void dap_common_deinit(void);
......@@ -332,13 +343,8 @@ void dap_log_set_max_item(unsigned int a_max);
// get logs from list
char *dap_log_get_item(time_t a_start_time, int a_limit);
#ifdef DAP_LOG_MT
void _log_it( const char * log_tag, enum dap_log_level, const char * format,... );
#define log_it( _log_level, ...) _log_it( LOG_TAG, _log_level, ##__VA_ARGS__)
#else
void _log_it2( const char *log_tag, enum dap_log_level ll, const char *fmt,... );
#define log_it( _log_level, ...) _log_it2( LOG_TAG, _log_level, ##__VA_ARGS__)
#endif
//void _vlog_it( const char * log_tag, uint32_t taglen, enum dap_log_level, const char * format, va_list ap );
//#define vlog_it( a_log_level, a_format, a_ap ) _vlog_it( LOG_TAG, sizeof(LOG_TAG)-1, a_log_level, a_format, a_ap )
......@@ -346,12 +352,15 @@ void _log_it2( const char *log_tag, enum dap_log_level ll, const char *fmt,... )
const char * log_error(void);
void dap_log_level_set(enum dap_log_level ll);
enum dap_log_level dap_log_level_get(void);
void dap_set_log_tag_width(size_t width);
const char * dap_get_appname();
void dap_set_appname(const char * a_appname);
char *dap_itoa(int i);
int dap_time_to_str_rfc822(char * out, size_t out_size_max, time_t t);
int timespec_diff(struct timespec *a_start, struct timespec *a_stop, struct timespec *a_result);
int get_select_breaker(void);
int send_select_break(void);
......
......@@ -22,12 +22,16 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include "utlist.h"
#include <dirent.h>
#ifndef _DAP_FILE_UTILS_H_
#define _DAP_FILE_UTILS_H_
#ifdef _WIN32
#include <Windows.h>
/* On Win32, the canonical directory separator is the backslash, and
* the search path separator is the semicolon. Note that also the
* (forward) slash works as directory separator.
......@@ -48,6 +52,11 @@
#endif
typedef struct dap_list_name_directories{
char *name_directory;
struct dap_list_name_directories *next;
}dap_list_name_directories_t;
/**
* Check the directory path for unsupported symbols
*
......@@ -85,4 +94,12 @@ char* dap_path_get_basename(const char *a_file_name);
bool dap_path_is_absolute(const char *a_file_name);
char* dap_path_get_dirname(const char *a_file_name);
/**
* Get list of subdirectories
*
* @a_path_name directory path.
* @return dap_list_t type variable that contains a list of subdirectories.
*/
dap_list_name_directories_t *dap_get_subs(const char *a_path_name);
#endif // _FILE_UTILS_H_
......@@ -74,7 +74,10 @@ char* dap_strdown(const char *a_str, ssize_t a_len);
char* dap_strreverse(char *a_string);
#ifdef _WIN32
char *strndup(char *str, unsigned long len);
#ifdef HAVE_STRNDUP
#define strndup(s, l) _strndup(s, l)
#endif
char *_strndup(char *str, unsigned long len);
#endif
#define DAP_USEC_PER_SEC 1000000
......
cmake_minimum_required(VERSION 3.0)
project (dap_core_android C)
file(GLOB CORE_ANDROID_SRCS *.c)
file(GLOB CORE_ANDROID_HEADERS *.h)
add_library(${PROJECT_NAME} STATIC ${CORE_ANDROID_SRCS} ${CORE_ANDROID_HEADERS})
#target_link_libraries(${PROJECT_NAME} dap_core pthread)
target_include_directories(${PROJECT_NAME} INTERFACE .)
#if __ANDROID_API__ < __ANDROID_API_N__
#include "pthread_barrier.h"
#include <errno.h>
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
{
if(count == 0)
{
errno = EINVAL;
return -1;
}
if(pthread_mutex_init(&barrier->mutex, 0) < 0)
{
return -2;
}
if(pthread_cond_init(&barrier->cond, 0) < 0)
{
pthread_mutex_destroy(&barrier->mutex);
return -3;
}
barrier->tripCount = count;
barrier->count = 0;
return 0;
}
int pthread_barrier_destroy(pthread_barrier_t *barrier)
{
pthread_cond_destroy(&barrier->cond);
pthread_mutex_destroy(&barrier->mutex);
return 0;
}
int pthread_barrier_wait(pthread_barrier_t *barrier)
{
pthread_mutex_lock(&barrier->mutex);
++(barrier->count);
if(barrier->count >= barrier->tripCount)
{
barrier->count = 0;
pthread_cond_broadcast(&barrier->cond);
pthread_mutex_unlock(&barrier->mutex);
return 1;
}
else
{
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
pthread_mutex_unlock(&barrier->mutex);
return 0;
}
}
#endif
#ifndef PTHREAD_BARRIER_H
#define PTHREAD_BARRIER_H
#include <pthread.h>
#if __ANDROID_API__ < __ANDROID_API_N__
typedef int pthread_barrierattr_t;
typedef struct
{
pthread_mutex_t mutex;
pthread_cond_t cond;
int count;
int tripCount;
} pthread_barrier_t;
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count);
int pthread_barrier_destroy(pthread_barrier_t *barrier);
int pthread_barrier_wait(pthread_barrier_t *barrier);
#endif // PTHREAD_BARRIER_H
#endif // PTHREAD_BARRIER_H
......@@ -21,7 +21,6 @@
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* 'nanosleep' */
......@@ -135,14 +134,13 @@ static unsigned int s_ansi_seq_color_len[16] = {0};
#endif
static volatile bool s_log_term_signal = false;
unsigned int l_sys_dir_path_len = 0;
char s_sys_dir_path[MAX_PATH] = {'\0'};
char* g_sys_dir_path = NULL;
static char s_last_error[LAST_ERROR_MAX] = {'\0'},
s_log_file_path[MAX_PATH] = {'\0'},
s_log_tag_fmt_str[10] = {'\0'};
static enum dap_log_level dap_log_level = L_DEBUG;
static enum dap_log_level s_dap_log_level = L_DEBUG;
static FILE *s_log_file = NULL;
#if DAP_LOG_USE_SPINLOCK
......@@ -151,7 +149,7 @@ static FILE *s_log_file = NULL;
static pthread_mutex_t s_log_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
static pthread_cond_t s_log_cond = PTHREAD_COND_INITIALIZER;
static volatile int count = 0;
static volatile int s_log_count = 0;
static pthread_t s_log_thread = 0;
static void *s_log_thread_proc(void *arg);
......@@ -162,7 +160,8 @@ typedef struct log_str_t {
struct log_str_t *prev, *next;
} log_str_t;
static log_str_t *log_buffer = NULL;
static log_str_t *s_log_buffer = NULL;
static char* s_appname = NULL;
DAP_STATIC_INLINE void s_update_log_time(char *a_datetime_str) {
time_t t = time(NULL);
......@@ -175,11 +174,31 @@ DAP_STATIC_INLINE void s_update_log_time(char *a_datetime_str) {
* @param[in] ll logging level
*/
void dap_log_level_set( enum dap_log_level a_ll ) {
dap_log_level = a_ll;
s_dap_log_level = a_ll;
}
/**
* @brief dap_get_appname
* @return
*/
const char * dap_get_appname()
{
return s_appname?s_appname: "dap";
}
/**
* @brief dap_set_appname
* @param a_appname
* @return
*/
void dap_set_appname(const char * a_appname)
{
s_appname = dap_strdup(a_appname);
}
enum dap_log_level dap_log_level_get( void ) {
return dap_log_level ;
return s_dap_log_level ;
}
/**
......@@ -210,6 +229,8 @@ int dap_common_init( const char *a_console_title, const char *a_log_filename ) {
s_ansi_seq_color_len[i] =(unsigned int) strlen(s_ansi_seq_color[i]);
if ( a_log_filename ) {
s_log_file = fopen( a_log_filename , "a" );
if( s_log_file == NULL)
s_log_file = fopen( a_log_filename , "w" );
if ( s_log_file == NULL ) {
dap_fprintf( stderr, "Can't open log file %s to append\n", a_log_filename );
return -1;
......@@ -220,6 +241,31 @@ int dap_common_init( const char *a_console_title, const char *a_log_filename ) {
return 0;
}
#ifdef WIN32
int wdap_common_init( const char *a_console_title, const wchar_t *a_log_filename ) {
// init randomer
srand( (unsigned int)time(NULL) );
(void) a_console_title;
strncpy( s_log_tag_fmt_str, "[%s]\t",sizeof (s_log_tag_fmt_str));
for (int i = 0; i < 16; ++i)
s_ansi_seq_color_len[i] =(unsigned int) strlen(s_ansi_seq_color[i]);
if ( a_log_filename ) {
s_log_file = _wfopen( a_log_filename , L"a" );
if( s_log_file == NULL)
s_log_file = _wfopen( a_log_filename , L"w" );
if ( s_log_file == NULL ) {
dap_fprintf( stderr, "Can't open log file %s to append\n", a_log_filename );
return -1;
}
//dap_stpcpy(s_log_file_path, a_log_filename);
}
pthread_create( &s_log_thread, NULL, s_log_thread_proc, NULL );
return 0;
}
#endif
/**
* @brief dap_common_deinit Deinitialise
*/
......@@ -237,9 +283,10 @@ void dap_common_deinit( ) {
* @return
*/
static void *s_log_thread_proc(void *arg) {
(void) arg;
for ( ; !s_log_term_signal; ) {
pthread_mutex_lock(&s_log_mutex);
for ( ; count == 0; ) {
for ( ; s_log_count == 0; ) {
pthread_cond_wait(&s_log_cond, &s_log_mutex);
}
log_str_t *elem, *tmp;
......@@ -249,14 +296,14 @@ static void *s_log_thread_proc(void *arg) {
s_log_file = fopen(s_log_file_path, "a");
}
}
DL_FOREACH_SAFE(log_buffer, elem, tmp) {
DL_FOREACH_SAFE(s_log_buffer, elem, tmp) {
if(s_log_file)
fwrite(elem->str + elem->offset, strlen(elem->str) - elem->offset, 1, s_log_file);
fwrite(elem->str, strlen(elem->str), 1, stdout);
DL_DELETE(log_buffer, elem);
DL_DELETE(s_log_buffer, elem);
DAP_FREE(elem);
--count;
--s_log_count;
if(s_log_file)
fflush(s_log_file);
......@@ -269,28 +316,41 @@ static void *s_log_thread_proc(void *arg) {
pthread_exit(NULL);
}
void _log_it(const char *log_tag, enum dap_log_level ll, const char *fmt, ...) {
if ( ll < dap_log_level || ll >= 16 || !log_tag )
/**
* @brief _log_it
* @param log_tag
* @param ll
* @param fmt
*/
void _log_it(const char *a_log_tag, enum dap_log_level a_ll, const char *a_fmt, ...) {
if ( a_ll < s_dap_log_level || a_ll >= 16 || !a_log_tag )
return;
log_str_t *log_string = DAP_NEW_Z(log_str_t);
strncpy(log_string->str, s_ansi_seq_color[ll],sizeof (log_string->str)-1);
log_string->offset = s_ansi_seq_color_len[ll];
s_update_log_time(log_string->str + log_string->offset);
size_t offset = strlen(log_string->str);
offset += dap_snprintf(log_string->str + offset, sizeof (log_string->str) -offset, "%s[%s%s", s_log_level_tag[ll], log_tag, "] ");
log_str_t *l_log_string = DAP_NEW_Z(log_str_t);
strncpy(l_log_string->str, s_ansi_seq_color[a_ll],sizeof (l_log_string->str)-1);
l_log_string->offset = s_ansi_seq_color_len[a_ll];
s_update_log_time(l_log_string->str + l_log_string->offset);
size_t offset = strlen(l_log_string->str);
offset += dap_snprintf(l_log_string->str + offset, sizeof (l_log_string->str) -offset, "%s[%s%s", s_log_level_tag[a_ll], a_log_tag, "] ");
va_list va;
va_start( va, fmt );
offset += dap_vsnprintf(log_string->str + offset,sizeof (log_string->str) -offset, fmt, va);
va_start( va, a_fmt );
offset += dap_vsnprintf(l_log_string->str + offset,sizeof (l_log_string->str) -offset, a_fmt, va);
va_end( va );
memcpy(&log_string->str[offset], "\n", 1);
memcpy(&l_log_string->str[offset], "\n", 1);
pthread_mutex_lock(&s_log_mutex);
DL_APPEND(log_buffer, log_string);
++count;
DL_APPEND(s_log_buffer, l_log_string);
++s_log_count;
pthread_cond_signal(&s_log_cond);
pthread_mutex_unlock(&s_log_mutex);
}
char *dap_log_get_item(time_t a_start_time, int a_limit) {
/**
* @brief dap_log_get_item
* @param a_start_time
* @param a_limit
* @return
*/
char *dap_log_get_item(time_t a_start_time, int a_limit)
{
return NULL; // TODO
}
......@@ -370,6 +430,32 @@ int dap_time_to_str_rfc822(char * out, size_t out_size_max, time_t t)
return ret;
}
/**
* @brief Calculate diff of two struct timespec
* @param[in] a_start - first time
* @param[in] a_stop - second time
* @param[out] a_result - diff time, may be NULL
* @return diff time in millisecond
*/
int timespec_diff(struct timespec *a_start, struct timespec *a_stop, struct timespec *a_result)
{
if(!a_start || !a_stop)
return 0;
if(!a_result) {
struct timespec l_time_tmp = { 0 };
a_result = &l_time_tmp;
}
if((a_stop->tv_nsec - a_start->tv_nsec) < 0) {
a_result->tv_sec = a_stop->tv_sec - a_start->tv_sec - 1;
a_result->tv_nsec = a_stop->tv_nsec - a_start->tv_nsec + 1000000000;
} else {
a_result->tv_sec = a_stop->tv_sec - a_start->tv_sec;
a_result->tv_nsec = a_stop->tv_nsec - a_start->tv_nsec;
}
return (a_result->tv_sec * 1000 + a_result->tv_nsec / 1000000);
}
#define BREAK_LATENCY 1
static int breaker_set[2] = { -1, -1 };
......
......@@ -368,3 +368,39 @@ char* dap_path_get_dirname(const char *a_file_name)
return l_base;
}
dap_list_name_directories_t *dap_get_subs(const char *a_path_dir){
dap_list_name_directories_t *list = NULL;
dap_list_name_directories_t *element;
#ifdef _WIN32
size_t m_size = strlen(a_path_dir);
char *m_path = DAP_NEW_SIZE(char, m_size + 2);
memcpy(m_path, a_path_dir, m_size);
m_path[m_size] = '*';
m_path[m_size + 1] = '\0';
WIN32_FIND_DATA info_file;
HANDLE h_find_file = FindFirstFileA(m_path, &info_file);
while (FindNextFileA(h_find_file, &info_file)){
if (info_file.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
element = (dap_list_name_directories_t *)malloc(sizeof(dap_list_name_directories_t));
element->name_directory = dap_strdup(info_file.cFileName);
LL_APPEND(list, element);
}
}
FindClose(h_find_file);
DAP_FREE(m_path);
#else
DIR *dir = opendir(a_path_dir);
struct dirent *entry = readdir(dir);
while (entry != NULL){
if (strcmp(entry->d_name, "..") != 0 && strcmp(entry->d_name, ".") != 0 && entry->d_type == DT_DIR){
element = (dap_list_name_directories_t *)malloc(sizeof(dap_list_name_directories_t));
element->name_directory = dap_strdup(entry->d_name);
LL_APPEND(list, element);
}
entry = readdir(dir);
}
closedir(dir);
#endif
return list;
}
......@@ -690,7 +690,7 @@ char *strptime( char *buff, const char *fmt, struct tm *tm ) {
return buff + len;
}
char *strndup(char *str, unsigned long len) {
char *_strndup(char *str, unsigned long len) {
char *buf = (char*)memchr(str, '\0', len);
if (buf)
len = buf - str;
......
......@@ -53,6 +53,11 @@ extern "C" {
//! Flag to rpaligned_realloc to not preserve content in reallocation
#define RPMALLOC_NO_PRESERVE 1
//redefinition from mman-linux.h For POSIX
#ifndef POSIX_MADV_DONTNEED
#define POSIX_MADV_DONTNEED 4/* Don't need these pages. */
#endif
typedef struct rpmalloc_global_statistics_t {
//! Current amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1)
size_t mapped;
......
......@@ -13,7 +13,13 @@ endif()
add_library(${PROJECT_NAME} STATIC ${CORE_UNIX_SRCS} ${CORE_UNIX_HEADERS}
${CORE_LINUX_SRCS} ${CORE_LINUX_HEADERS})
target_link_libraries(${PROJECT_NAME} dap_core pthread)
target_link_libraries(${PROJECT_NAME} dap_core)
if (ANDROID)
target_link_libraries(${PROJECT_NAME} dap_core_android)
else()
target_link_libraries(${PROJECT_NAME} pthread)
endif()
target_include_directories(dap_core_unix INTERFACE .)
......
......@@ -6,6 +6,9 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#ifdef __ANDROID__
#include "pthread_barrier.h"
#endif
#include "dap_network_monitor.h"
#include "dap_common.h"
......
cmake_minimum_required(VERSION 3.0)
project (dap_core_win32 C)
file(GLOB CORE_SRCS *.c)
file(GLOB CORE_HEADERS *.h)
add_library(${PROJECT_NAME} STATIC ${CORE_SRCS} ${CORE_HEADERS})
target_include_directories(${PROJECT_NAME} INTERFACE .)
\ No newline at end of file
......@@ -13,16 +13,31 @@ wchar_t* readRegKey(HKEY hKey, LPCWSTR regSubKey, LPCWSTR val) {
}
char* regGetUsrPath() {
static char path[MAX_PATH] = {};
static char path[MAX_PATH] = {'\0'};
if (strlen(path) > 3) { return path; }
HKEY hKey;
const char keyPath[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
LSTATUS err = RegOpenKeyExA(HKEY_CURRENT_USER,
LSTATUS err = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
keyPath,
0, KEY_READ, &hKey );
if (err != ERROR_SUCCESS) { return NULL; }
DWORD len = MAX_PATH;
err = RegGetValueA(hKey, NULL, "Personal", RRF_RT_REG_SZ, NULL, (void*)path, &len);
err = RegGetValueA(hKey, NULL, "Common Documents", RRF_RT_REG_SZ, NULL, (void*)path, &len);
RegCloseKey(hKey);
return path;
}
wchar_t* regWGetUsrPath() {
static wchar_t path[MAX_PATH] = {'\0'};
if (wcslen(path) > 3) { return path; }
HKEY hKey;
const char keyPath[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
LSTATUS err = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
keyPath,
0, KEY_READ, &hKey );
if (err != ERROR_SUCCESS) { return NULL; }
DWORD len = MAX_PATH;
err = RegGetValueW(hKey, NULL, L"Common Documents", RRF_RT_REG_SZ, NULL, (void*)path, &len);
RegCloseKey(hKey);
return path;
}
......
......@@ -14,7 +14,8 @@ wchar_t* getTapGUID();
wchar_t* getTapName();
wchar_t* getUserSID(LPCWSTR homePath);
char* regGetUsrPath();
wchar_t* regWGetUsrPath();
char* regGetUsrPath();
#ifdef __cplusplus
}
......