function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
canonical_perm_path
|
canonical_perm_path (const char *path)
{
int len = strlen(path);
char *copy, *ret;
if (strcmp (path, "/") == 0)
return g_strdup(path);
if (path[0] == '/' && path[len-1] != '/')
return g_strdup(path);
copy = g_strdup(path);
if (copy[len-1] == '/')
copy[len-1] = 0;
if (copy[0] != '/')
ret = g_strconcat ("/", copy, NULL);
else
ret = copy;
return ret;
}
|
/* Make sure the path starts with '/' but doesn't end with '/'. */
|
Make sure the path starts with '/' but doesn't end with '/'.
|
add_handle_to_iocp
|
add_handle_to_iocp (SeafWTMonitor *monitor, HANDLE hAdd)
{
SeafWTMonitorPriv *priv = monitor->priv;
if (!priv || !hAdd)
return FALSE;
/* CreateIoCompletionPort() will add the handle to an I/O Completion Port
if the iocp handle is not NULL. Otherwise it will create a new IOCP
handle.
The `key' parameter is used by th IOCP to tell us which handle watched
by the I/O Completion Port triggeed a return of the
GetQueuedCompletionStatus() function.
Here we use the value of the handle itself as the key for this handle
in the I/O Completion Port.
*/
priv->iocp_handle = CreateIoCompletionPort
(hAdd, /* handle to add */
priv->iocp_handle, /* iocp handle */
(ULONG_PTR)hAdd, /* key for this handle */
1); /* Num of concurrent threads */
if (!priv->iocp_handle) {
seaf_warning ("failed to create/add iocp, error code %lu",
GetLastError());
return FALSE;
}
if (hAdd == (HANDLE)monitor->cmd_pipe[0]) {
/* HANDLE is cmd_pipe */
return start_watch_cmd_pipe (monitor, NULL);
} else {
/* HANDLE is a dir handle */
return start_watch_dir_change (priv, hAdd);
}
}
|
/* Add a specific HANDLE to an I/O Completion Port. If it's the cmd pipe
* handle, call ReadFile() on it; If it's a dir handle, call
* ReadDirectoryChangesW() on it.
*/
|
Add a specific HANDLE to an I/O Completion Port. If it's the cmd pipe handle, call ReadFile() on it; If it's a dir handle, call ReadDirectoryChangesW() on it.
|
get_handle_of_path
|
get_handle_of_path(const wchar_t *path)
{
HANDLE dir_handle = NULL;
dir_handle = CreateFileW
(path, /* file name */
FILE_LIST_DIRECTORY, /* desired access */
FILE_SHARE_DELETE | FILE_SHARE_READ
| FILE_SHARE_WRITE, /* share mode */
NULL, /* securitry attr */
OPEN_EXISTING, /* open options */
FILE_FLAG_BACKUP_SEMANTICS |
FILE_FLAG_OVERLAPPED, /* flags needed for asynchronous IO*/
NULL); /* template file */
if (dir_handle == INVALID_HANDLE_VALUE) {
char *path_utf8 = g_utf16_to_utf8 (path, -1, NULL, NULL, NULL);
seaf_warning("failed to create dir handle for path %s, "
"error code %lu", path_utf8, GetLastError());
g_free (path_utf8);
return NULL;
}
return dir_handle;
}
|
/* Get the HANDLE of a repo directory, for latter use in
* ReadDirectoryChangesW(). This handle should be closed when the repo is
* unwatched.
*/
|
Get the HANDLE of a repo directory, for latter use in ReadDirectoryChangesW(). This handle should be closed when the repo is unwatched.
|
seaf_clone_manager_gen_default_worktree
|
seaf_clone_manager_gen_default_worktree (SeafCloneManager *mgr,
const char *worktree_parent,
const char *repo_name)
{
char *wt = g_build_filename (worktree_parent, repo_name, NULL);
char *worktree;
worktree = make_worktree (mgr, wt, TRUE, NULL);
if (!worktree)
return wt;
g_free (wt);
return worktree;
}
|
/*
* Generate a conflict-free path to be used as worktree.
* This worktree path can be used as the @worktree parameter
* for seaf_clone_manager_add_task().
*/
|
Generate a conflict-free path to be used as worktree. This worktree path can be used as the @worktree parameter for seaf_clone_manager_add_task().
|
get_argv_utf8
|
get_argv_utf8 (int *argc)
{
int i = 0;
char **argv = NULL;
const wchar_t *cmdline = NULL;
wchar_t **argv_w = NULL;
cmdline = GetCommandLineW();
argv_w = CommandLineToArgvW (cmdline, argc);
if (!argv_w) {
printf("failed to CommandLineToArgvW(), GLE=%lu\n", GetLastError());
return NULL;
}
argv = (char **)malloc (sizeof(char*) * (*argc));
for (i = 0; i < *argc; i++) {
argv[i] = wchar_to_utf8 (argv_w[i]);
}
return argv;
}
|
/* Get the commandline arguments in unicode, then convert them to utf8 */
|
Get the commandline arguments in unicode, then convert them to utf8
|
commit_tree_from_changeset
|
commit_tree_from_changeset (ChangeSet *changeset)
{
gint64 mtime;
char *root_id = commit_tree_recursive (changeset->repo_id,
changeset->tree_root,
&mtime);
return root_id;
}
|
/*
* This function does two things:
* - calculate dir id from bottom up;
* - create and save seaf dir objects.
* It returns root dir id of the new commit.
*/
|
This function does two things: - calculate dir id from bottom up; - create and save seaf dir objects. It returns root dir id of the new commit.
|
need_notify_sync
|
need_notify_sync (SeafRepo *repo)
{
char *notify_setting = seafile_session_config_get_string(seaf, "notify_sync");
if (notify_setting == NULL) {
seafile_session_config_set_string(seaf, "notify_sync", "on");
return TRUE;
}
gboolean result = (g_strcmp0(notify_setting, "on") == 0);
g_free (notify_setting);
return result;
}
|
/* Check the notify setting by user. */
|
Check the notify setting by user.
|
check_locked_file_before_remove
|
check_locked_file_before_remove (LockedFileSet *fset, const char *path)
{
#if defined WIN32 || defined __APPLE__
if (!fset)
return TRUE;
LockedFile *file = locked_file_set_lookup (fset, path);
gboolean ret = TRUE;
if (file)
ret = FALSE;
return ret;
#else
return TRUE;
#endif
}
|
/* Returns whether the file should be removed from index. */
|
Returns whether the file should be removed from index.
|
ignore_xlsx_update
|
ignore_xlsx_update (const char *src_path, const char *dst_path)
{
GPatternSpec *pattern = g_pattern_spec_new ("*.xlsx");
int ret = FALSE;
if (!g_pattern_match_string(pattern, src_path) &&
g_pattern_match_string(pattern, dst_path))
ret = TRUE;
g_pattern_spec_free (pattern);
return ret;
}
|
/* Excel first writes update to a temporary file and then rename the file to
* xlsx. Unfortunately the temp file dosen't have specific pattern.
* We can only ignore renaming from non xlsx file to xlsx file.
*/
|
Excel first writes update to a temporary file and then rename the file to xlsx. Unfortunately the temp file dosen't have specific pattern. We can only ignore renaming from non xlsx file to xlsx file.
|
move_repo_stores
|
move_repo_stores (SeafRepoManager *mgr, SeafRepo *repo)
{
seaf_repo_manager_move_repo_store (mgr, "commits", repo->id);
seaf_repo_manager_move_repo_store (mgr, "fs", repo->id);
}
|
/* Move commits, fs stores into "deleted_store" directory. */
|
Move commits, fs stores into "deleted_store" directory.
|
seaf_repo_manager_get_repo
|
seaf_repo_manager_get_repo (SeafRepoManager *manager, const gchar *id)
{
SeafRepo *res;
if (pthread_rwlock_rdlock (&manager->priv->lock) < 0) {
seaf_warning ("[repo mgr] failed to lock repo cache.\n");
return NULL;
}
res = g_hash_table_lookup (manager->priv->repo_hash, id);
pthread_rwlock_unlock (&manager->priv->lock);
if (res && !res->delete_pending)
return res;
return NULL;
}
|
/*
Return the internal Repo in hashtable. The caller should not free the returned Repo.
*/
|
Return the internal Repo in hashtable. The caller should not free the returned Repo.
|
seaf_repo_free_ignore_files
|
void seaf_repo_free_ignore_files (GList *ignore_list)
{
GList *p;
if (ignore_list == NULL)
return;
for (p = ignore_list; p != NULL; p = p->next)
free(p->data);
g_list_free (ignore_list);
}
|
/*
* Free ignored file list
*/
|
Free ignored file list
|
is_valid_ipaddr
|
is_valid_ipaddr (const char *addr_str)
{
struct sockaddr_storage addr;
if (!addr_str)
return 0;
if (sock_pton(addr_str, 0, &addr) < 0)
return 0;
return 1;
}
|
/* return 1 if addr_str is a valid ipv4 or ipv6 address */
|
return 1 if addr_str is a valid ipv4 or ipv6 address
|
readn
|
readn(int fd, void *vptr, size_t n)
{
size_t nleft;
ssize_t nread;
char *ptr;
ptr = vptr;
nleft = n;
while (nleft > 0) {
if ( (nread = read(fd, ptr, nleft)) < 0) {
if (errno == EINTR)
nread = 0; /* and call read() again */
else
return(-1);
} else if (nread == 0)
break; /* EOF */
nleft -= nread;
ptr += nread;
}
return(n - nleft); /* return >= 0 */
}
|
/* Read "n" bytes from a descriptor. */
|
Read "n" bytes from a descriptor.
|
writen
|
writen(int fd, const void *vptr, size_t n)
{
size_t nleft;
ssize_t nwritten;
const char *ptr;
ptr = vptr;
nleft = n;
while (nleft > 0) {
if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
if (nwritten < 0 && errno == EINTR)
nwritten = 0; /* and call write() again */
else
return(-1); /* error */
}
nleft -= nwritten;
ptr += nwritten;
}
return(n);
}
|
/* Write "n" bytes to a descriptor. */
|
Write "n" bytes to a descriptor.
|
recvn
|
recvn(evutil_socket_t fd, void *vptr, size_t n)
{
size_t nleft;
ssize_t nread;
char *ptr;
ptr = vptr;
nleft = n;
while (nleft > 0) {
#ifndef WIN32
if ( (nread = read(fd, ptr, nleft)) < 0)
#else
if ( (nread = recv(fd, ptr, nleft, 0)) < 0)
#endif
{
if (errno == EINTR)
nread = 0; /* and call read() again */
else
return(-1);
} else if (nread == 0)
break; /* EOF */
nleft -= nread;
ptr += nread;
}
return(n - nleft); /* return >= 0 */
}
|
/* Read "n" bytes from a descriptor. */
|
Read "n" bytes from a descriptor.
|
sendn
|
sendn(evutil_socket_t fd, const void *vptr, size_t n)
{
size_t nleft;
ssize_t nwritten;
const char *ptr;
ptr = vptr;
nleft = n;
while (nleft > 0) {
#ifndef WIN32
if ( (nwritten = write(fd, ptr, nleft)) <= 0)
#else
if ( (nwritten = send(fd, ptr, nleft, 0)) <= 0)
#endif
{
if (nwritten < 0 && errno == EINTR)
nwritten = 0; /* and call write() again */
else
return(-1); /* error */
}
nleft -= nwritten;
ptr += nwritten;
}
return(n);
}
|
/* Write "n" bytes to a descriptor. */
|
Write "n" bytes to a descriptor.
|
ccnet_key_file_get_string
|
ccnet_key_file_get_string (GKeyFile *keyf,
const char *category,
const char *key)
{
gchar *v;
if (!g_key_file_has_key (keyf, category, key, NULL))
return NULL;
v = g_key_file_get_string (keyf, category, key, NULL);
if (v != NULL && v[0] == '\0') {
g_free(v);
return NULL;
}
return v;
}
|
/**
* handle the empty string problem.
*/
|
handle the empty string problem.
|
ccnet_locale_to_utf8
|
char *ccnet_locale_to_utf8 (const gchar *src)
{
if (!src)
return NULL;
gsize bytes_read = 0;
gsize bytes_written = 0;
GError *error = NULL;
gchar *dst = NULL;
dst = g_locale_to_utf8
(src, /* locale specific string */
strlen(src), /* len of src */
&bytes_read, /* length processed */
&bytes_written, /* output length */
&error);
if (error) {
return NULL;
}
return dst;
}
|
/* convert locale specific input to utf8 encoded string */
|
convert locale specific input to utf8 encoded string
|
ccnet_locale_from_utf8
|
char *ccnet_locale_from_utf8 (const gchar *src)
{
if (!src)
return NULL;
gsize bytes_read = 0;
gsize bytes_written = 0;
GError *error = NULL;
gchar *dst = NULL;
dst = g_locale_from_utf8
(src, /* locale specific string */
strlen(src), /* len of src */
&bytes_read, /* length processed */
&bytes_written, /* output length */
&error);
if (error) {
return NULL;
}
return dst;
}
|
/* convert utf8 input to locale specific string */
|
convert utf8 input to locale specific string
|
find_process_in_dirent
|
find_process_in_dirent(struct dirent *dir, const char *process_name)
{
char path[512];
/* fisrst construct a path like /proc/123/exe */
if (sprintf (path, "/proc/%s/exe", dir->d_name) < 0) {
return -1;
}
char buf[SEAF_PATH_MAX];
/* get the full path of exe */
ssize_t l = readlink(path, buf, SEAF_PATH_MAX);
if (l < 0)
return -1;
buf[l] = '\0';
/* get the base name of exe */
char *base = g_path_get_basename(buf);
int ret = strcmp(base, process_name);
g_free(base);
if (ret == 0)
return atoi(dir->d_name);
else
return -1;
}
|
/* read the link of /proc/123/exe and compare with `process_name' */
|
read the link of /proc/123/exe and compare with `process_name'
|
process_is_running
|
gboolean process_is_running (const char *process_name)
{
DIR *proc_dir = opendir("/proc");
if (!proc_dir) {
fprintf (stderr, "failed to open /proc/ dir\n");
return FALSE;
}
struct dirent *subdir = NULL;
while ((subdir = readdir(proc_dir))) {
char first = subdir->d_name[0];
/* /proc/[1-9][0-9]* */
if (first > '9' || first < '1')
continue;
int pid = find_process_in_dirent(subdir, process_name);
if (pid > 0) {
closedir(proc_dir);
return TRUE;
}
}
closedir(proc_dir);
return FALSE;
}
|
/* read the /proc fs to determine whether some process is running */
|
read the /proc fs to determine whether some process is running
|
strtok_r
|
strtok_r(char *s, const char *delim, char **save_ptr)
{
char *token;
if(s == NULL)
s = *save_ptr;
/* Scan leading delimiters. */
s += strspn(s, delim);
if(*s == '\0') {
*save_ptr = s;
return NULL;
}
/* Find the end of the token. */
token = s;
s = strpbrk(token, delim);
if(s == NULL) {
/* This token finishes the string. */
*save_ptr = strchr(token, '\0');
} else {
/* Terminate the token and make *SAVE_PTR point past it. */
*s = '\0';
*save_ptr = s + 1;
}
return token;
}
|
/*
* strtok_r code directly from glibc.git /string/strtok_r.c since windows
* doesn't have it.
*/
|
strtok_r code directly from glibc.git /string/strtok_r.c since windows doesn't have it.
|
is_fast_forward
|
is_fast_forward (const char *repo_id, int version,
const char *src_head, const char *dst_head)
{
VCCompareResult res;
res = vc_compare_commits (repo_id, version, src_head, dst_head);
return (res == VC_FAST_FORWARD);
}
|
/*
* Returns true if src_head is ahead of dst_head.
*/
|
Returns true if src_head is ahead of dst_head.
|
get_file_modifier_mtime
|
get_file_modifier_mtime (const char *repo_id,
const char *store_id,
int version,
const char *head,
const char *path,
char **modifier,
gint64 *mtime)
{
if (version > 0)
return get_file_modifier_mtime_v1 (repo_id, store_id, version,
head, path,
modifier, mtime);
else
return get_file_modifier_mtime_v0 (repo_id, store_id, version,
head, path,
modifier, mtime);
}
|
/**
* Get the user who last changed a file and the mtime.
* @head: head commit to start the search.
* @path: path of the file.
*/
|
Get the user who last changed a file and the mtime. @head: head commit to start the search. @path: path of the file.
|
remove_index_entry_at
|
int remove_index_entry_at(struct index_state *istate, int pos)
{
struct cache_entry *ce = istate->cache[pos];
/* record_resolve_undo(istate, ce); */
remove_name_hash(istate, ce);
cache_entry_free (ce);
istate->cache_changed = 1;
istate->cache_nr--;
if (pos >= istate->cache_nr)
return 0;
memmove(istate->cache + pos,
istate->cache + pos + 1,
(istate->cache_nr - pos) * sizeof(struct cache_entry *));
return 1;
}
|
/* Remove entry, return true if there are more entries to go.. */
|
Remove entry, return true if there are more entries to go..
|
remove_marked_cache_entries
|
void remove_marked_cache_entries(struct index_state *istate)
{
struct cache_entry **ce_array = istate->cache;
unsigned int i, j;
gboolean removed = FALSE;
for (i = j = 0; i < istate->cache_nr; i++) {
if (ce_array[i]->ce_flags & CE_REMOVE) {
remove_name_hash(istate, ce_array[i]);
cache_entry_free (ce_array[i]);
removed = TRUE;
} else {
ce_array[j++] = ce_array[i];
}
}
if (removed) {
istate->cache_changed = 1;
istate->cache_nr = j;
}
}
|
/*
* Remove all cache ententries marked for removal, that is where
* CE_REMOVE is set in ce_flags. This is much more effective than
* calling remove_index_entry_at() for each entry to be removed.
*/
|
Remove all cache ententries marked for removal, that is where CE_REMOVE is set in ce_flags. This is much more effective than calling remove_index_entry_at() for each entry to be removed.
|
icase_hash
|
static inline unsigned char icase_hash(unsigned char c)
{
return c & ~((c & 0x40) >> 1);
}
|
/*
* This removes bit 5 if bit 6 is set.
*
* That will make US-ASCII characters hash to their upper-case
* equivalent. We could easily do this one whole word at a time,
* but that's for future worries.
*/
|
This removes bit 5 if bit 6 is set.
That will make US-ASCII characters hash to their upper-case equivalent. We could easily do this one whole word at a time, but that's for future worries.
|
lookup_hash_entry
|
static struct hash_table_entry *lookup_hash_entry(unsigned int hash, const struct hash_table *table)
{
unsigned int size = table->size, nr = hash % size;
struct hash_table_entry *array = table->array;
while (array[nr].ptr) {
if (array[nr].hash == hash)
break;
nr++;
if (nr >= size)
nr = 0;
}
return array + nr;
}
|
/*
* Look up a hash entry in the hash table. Return the pointer to
* the existing entry, or the empty slot if none existed. The caller
* can then look at the (*ptr) to see whether it existed or not.
*/
|
Look up a hash entry in the hash table. Return the pointer to the existing entry, or the empty slot if none existed. The caller can then look at the (*ptr) to see whether it existed or not.
|
insert_hash_entry
|
static void **insert_hash_entry(unsigned int hash, void *ptr, struct hash_table *table)
{
struct hash_table_entry *entry = lookup_hash_entry(hash, table);
if (!entry->ptr) {
entry->ptr = ptr;
entry->hash = hash;
table->nr++;
return NULL;
}
return &entry->ptr;
}
|
/*
* Insert a new hash entry pointer into the table.
*
* If that hash entry already existed, return the pointer to
* the existing entry (and the caller can create a list of the
* pointers or do anything else). If it didn't exist, return
* NULL (and the caller knows the pointer has been inserted).
*/
|
Insert a new hash entry pointer into the table.
If that hash entry already existed, return the pointer to the existing entry (and the caller can create a list of the pointers or do anything else). If it didn't exist, return NULL (and the caller knows the pointer has been inserted).
|
fls32
|
static inline u_int fls32 (u_int32_t v)
{
if (v & 0xffff0000) {
if (v & 0xff000000)
return 24 + bytemsb[v>>24];
else
return 16 + bytemsb[v>>16];
}
if (v & 0x0000ff00)
return 8 + bytemsb[v>>8];
else
return bytemsb[v];
}
|
/* Find last set (most significant bit) */
|
Find last set (most significant bit)
|
rabin_checksum
|
unsigned int rabin_checksum(char *buf, int len)
{
int i;
unsigned int sum = 0;
for (i = 0; i < len; ++i) {
sum = rabin_rolling_checksum (sum, len, 0, buf[i]);
}
return sum;
}
|
/*
* a simple 32 bit checksum that can be upadted from end
*/
|
a simple 32 bit checksum that can be upadted from end
|
isValidString
|
static bool isValidString(const void* const address)
{
if((void*)address == NULL)
{
return false;
}
char buffer[500];
if((uintptr_t)address+sizeof(buffer) < (uintptr_t)address)
{
// Wrapped around the address range.
return false;
}
if(!ksmem_copySafely(address, buffer, sizeof(buffer)))
{
return false;
}
return ksstring_isNullTerminatedUTF8String(buffer, kMinStringLength, sizeof(buffer));
}
|
/** Check if a memory address points to a valid null terminated UTF-8 string.
*
* @param address The address to check.
*
* @return true if the address points to a string.
*/
|
Check if a memory address points to a valid null terminated UTF-8 string.
@param address The address to check.
@return true if the address points to a string.
|
getStackCursor
|
static bool getStackCursor(const KSCrash_MonitorContext* const crash,
const struct KSMachineContext* const machineContext,
KSStackCursor *cursor)
{
if(ksmc_getThreadFromContext(machineContext) == ksmc_getThreadFromContext(crash->offendingMachineContext))
{
*cursor = *((KSStackCursor*)crash->stackCursor);
return true;
}
kssc_initWithMachineContext(cursor, KSSC_STACK_OVERFLOW_THRESHOLD, machineContext);
return true;
}
|
/** Get the backtrace for the specified machine context.
*
* This function will choose how to fetch the backtrace based on the crash and
* machine context. It may store the backtrace in backtraceBuffer unless it can
* be fetched directly from memory. Do not count on backtraceBuffer containing
* anything. Always use the return value.
*
* @param crash The crash handler context.
*
* @param machineContext The machine context.
*
* @param cursor The stack cursor to fill.
*
* @return True if the cursor was filled.
*/
|
Get the backtrace for the specified machine context.
This function will choose how to fetch the backtrace based on the crash and machine context. It may store the backtrace in backtraceBuffer unless it can be fetched directly from memory. Do not count on backtraceBuffer containing anything. Always use the return value.
@param crash The crash handler context.
@param machineContext The machine context.
@param cursor The stack cursor to fill.
@return True if the cursor was filled.
|
writeNSStringContents
|
static void writeNSStringContents(const KSCrashReportWriter* const writer,
const char* const key,
const uintptr_t objectAddress,
__unused int* limit)
{
const void* object = (const void*)objectAddress;
char buffer[200];
if(ksobjc_copyStringContents(object, buffer, sizeof(buffer)))
{
writer->addStringElement(writer, key, buffer);
}
}
|
/** Write a string to the report.
* This will only print the first child of the array.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param objectAddress The object's address.
*
* @param limit How many more subreferenced objects to write, if any.
*/
|
Write a string to the report. This will only print the first child of the array.
@param writer The writer.
@param key The object key, if needed.
@param objectAddress The object's address.
@param limit How many more subreferenced objects to write, if any.
|
writeURLContents
|
static void writeURLContents(const KSCrashReportWriter* const writer,
const char* const key,
const uintptr_t objectAddress,
__unused int* limit)
{
const void* object = (const void*)objectAddress;
char buffer[200];
if(ksobjc_copyStringContents(object, buffer, sizeof(buffer)))
{
writer->addStringElement(writer, key, buffer);
}
}
|
/** Write a URL to the report.
* This will only print the first child of the array.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param objectAddress The object's address.
*
* @param limit How many more subreferenced objects to write, if any.
*/
|
Write a URL to the report. This will only print the first child of the array.
@param writer The writer.
@param key The object key, if needed.
@param objectAddress The object's address.
@param limit How many more subreferenced objects to write, if any.
|
writeDateContents
|
static void writeDateContents(const KSCrashReportWriter* const writer,
const char* const key,
const uintptr_t objectAddress,
__unused int* limit)
{
const void* object = (const void*)objectAddress;
writer->addFloatingPointElement(writer, key, ksobjc_dateContents(object));
}
|
/** Write a date to the report.
* This will only print the first child of the array.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param objectAddress The object's address.
*
* @param limit How many more subreferenced objects to write, if any.
*/
|
Write a date to the report. This will only print the first child of the array.
@param writer The writer.
@param key The object key, if needed.
@param objectAddress The object's address.
@param limit How many more subreferenced objects to write, if any.
|
writeNumberContents
|
static void writeNumberContents(const KSCrashReportWriter* const writer,
const char* const key,
const uintptr_t objectAddress,
__unused int* limit)
{
const void* object = (const void*)objectAddress;
writer->addFloatingPointElement(writer, key, ksobjc_numberAsFloat(object));
}
|
/** Write a number to the report.
* This will only print the first child of the array.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param objectAddress The object's address.
*
* @param limit How many more subreferenced objects to write, if any.
*/
|
Write a number to the report. This will only print the first child of the array.
@param writer The writer.
@param key The object key, if needed.
@param objectAddress The object's address.
@param limit How many more subreferenced objects to write, if any.
|
writeArrayContents
|
static void writeArrayContents(const KSCrashReportWriter* const writer,
const char* const key,
const uintptr_t objectAddress,
int* limit)
{
const void* object = (const void*)objectAddress;
uintptr_t firstObject = 0;
if(ksobjc_arrayContents(object, &firstObject, 1) == 1)
{
writeMemoryContents(writer, key, firstObject, limit);
}
}
|
/** Write an array to the report.
* This will only print the first child of the array.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param objectAddress The object's address.
*
* @param limit How many more subreferenced objects to write, if any.
*/
|
Write an array to the report. This will only print the first child of the array.
@param writer The writer.
@param key The object key, if needed.
@param objectAddress The object's address.
@param limit How many more subreferenced objects to write, if any.
|
writeMemoryContentsIfNotable
|
static void writeMemoryContentsIfNotable(const KSCrashReportWriter* const writer,
const char* const key,
const uintptr_t address)
{
if(isNotableAddress(address))
{
int limit = kDefaultMemorySearchDepth;
writeMemoryContents(writer, key, address, &limit);
}
}
|
/** Write the contents of a memory location only if it contains notable data.
* Also writes meta information about the data.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param address The memory address.
*/
|
Write the contents of a memory location only if it contains notable data. Also writes meta information about the data.
@param writer The writer.
@param key The object key, if needed.
@param address The memory address.
|
writeAddressReferencedByString
|
static void writeAddressReferencedByString(const KSCrashReportWriter* const writer,
const char* const key,
const char* string)
{
uint64_t address = 0;
if(string == NULL || !ksstring_extractHexValue(string, (int)strlen(string), &address))
{
return;
}
int limit = kDefaultMemorySearchDepth;
writeMemoryContents(writer, key, (uintptr_t)address, &limit);
}
|
/** Look for a hex value in a string and try to write whatever it references.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param string The string to search.
*/
|
Look for a hex value in a string and try to write whatever it references.
@param writer The writer.
@param key The object key, if needed.
@param string The string to search.
|
writeBasicRegisters
|
static void writeBasicRegisters(const KSCrashReportWriter* const writer,
const char* const key,
const struct KSMachineContext* const machineContext)
{
char registerNameBuff[30];
const char* registerName;
writer->beginObject(writer, key);
{
const int numRegisters = kscpu_numRegisters();
for(int reg = 0; reg < numRegisters; reg++)
{
registerName = kscpu_registerName(reg);
if(registerName == NULL)
{
snprintf(registerNameBuff, sizeof(registerNameBuff), "r%d", reg);
registerName = registerNameBuff;
}
writer->addUIntegerElement(writer, registerName,
kscpu_registerValue(machineContext, reg));
}
}
writer->endContainer(writer);
}
|
/** Write the contents of all regular registers to the report.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param machineContext The context to retrieve the registers from.
*/
|
Write the contents of all regular registers to the report.
@param writer The writer.
@param key The object key, if needed.
@param machineContext The context to retrieve the registers from.
|
writeExceptionRegisters
|
static void writeExceptionRegisters(const KSCrashReportWriter* const writer,
const char* const key,
const struct KSMachineContext* const machineContext)
{
char registerNameBuff[30];
const char* registerName;
writer->beginObject(writer, key);
{
const int numRegisters = kscpu_numExceptionRegisters();
for(int reg = 0; reg < numRegisters; reg++)
{
registerName = kscpu_exceptionRegisterName(reg);
if(registerName == NULL)
{
snprintf(registerNameBuff, sizeof(registerNameBuff), "r%d", reg);
registerName = registerNameBuff;
}
writer->addUIntegerElement(writer,registerName,
kscpu_exceptionRegisterValue(machineContext, reg));
}
}
writer->endContainer(writer);
}
|
/** Write the contents of all exception registers to the report.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param machineContext The context to retrieve the registers from.
*/
|
Write the contents of all exception registers to the report.
@param writer The writer.
@param key The object key, if needed.
@param machineContext The context to retrieve the registers from.
|
writeRegisters
|
static void writeRegisters(const KSCrashReportWriter* const writer,
const char* const key,
const struct KSMachineContext* const machineContext)
{
writer->beginObject(writer, key);
{
writeBasicRegisters(writer, KSCrashField_Basic, machineContext);
if(ksmc_hasValidExceptionRegisters(machineContext))
{
writeExceptionRegisters(writer, KSCrashField_Exception, machineContext);
}
}
writer->endContainer(writer);
}
|
/** Write all applicable registers.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param machineContext The context to retrieve the registers from.
*/
|
Write all applicable registers.
@param writer The writer.
@param key The object key, if needed.
@param machineContext The context to retrieve the registers from.
|
writeNotableRegisters
|
static void writeNotableRegisters(const KSCrashReportWriter* const writer,
const struct KSMachineContext* const machineContext)
{
char registerNameBuff[30];
const char* registerName;
const int numRegisters = kscpu_numRegisters();
for(int reg = 0; reg < numRegisters; reg++)
{
registerName = kscpu_registerName(reg);
if(registerName == NULL)
{
snprintf(registerNameBuff, sizeof(registerNameBuff), "r%d", reg);
registerName = registerNameBuff;
}
writeMemoryContentsIfNotable(writer,
registerName,
(uintptr_t)kscpu_registerValue(machineContext, reg));
}
}
|
/** Write any notable addresses contained in the CPU registers.
*
* @param writer The writer.
*
* @param machineContext The context to retrieve the registers from.
*/
|
Write any notable addresses contained in the CPU registers.
@param writer The writer.
@param machineContext The context to retrieve the registers from.
|
writeNotableAddresses
|
static void writeNotableAddresses(const KSCrashReportWriter* const writer,
const char* const key,
const struct KSMachineContext* const machineContext)
{
writer->beginObject(writer, key);
{
writeNotableRegisters(writer, machineContext);
writeNotableStackContents(writer,
machineContext,
kStackNotableSearchBackDistance,
kStackNotableSearchForwardDistance);
}
writer->endContainer(writer);
}
|
/** Write any notable addresses in the stack or registers to the report.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param machineContext The context to retrieve the registers from.
*/
|
Write any notable addresses in the stack or registers to the report.
@param writer The writer.
@param key The object key, if needed.
@param machineContext The context to retrieve the registers from.
|
writeBinaryImages
|
static void writeBinaryImages(const KSCrashReportWriter* const writer, const char* const key)
{
const int imageCount = ksdl_imageCount();
writer->beginArray(writer, key);
{
for(int iImg = 0; iImg < imageCount; iImg++)
{
writeBinaryImage(writer, NULL, iImg);
}
}
writer->endContainer(writer);
}
|
/** Write information about all images to the report.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*/
|
Write information about all images to the report.
@param writer The writer.
@param key The object key, if needed.
|
writeMemoryInfo
|
static void writeMemoryInfo(const KSCrashReportWriter* const writer,
const char* const key,
const KSCrash_MonitorContext* const monitorContext)
{
writer->beginObject(writer, key);
{
writer->addUIntegerElement(writer, KSCrashField_Size, monitorContext->System.memorySize);
writer->addUIntegerElement(writer, KSCrashField_Usable, monitorContext->System.usableMemory);
writer->addUIntegerElement(writer, KSCrashField_Free, monitorContext->System.freeMemory);
}
writer->endContainer(writer);
}
|
/** Write information about system memory to the report.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*/
|
Write information about system memory to the report.
@param writer The writer.
@param key The object key, if needed.
|
writeProcessState
|
static void writeProcessState(const KSCrashReportWriter* const writer,
const char* const key,
const KSCrash_MonitorContext* const monitorContext)
{
writer->beginObject(writer, key);
{
if(monitorContext->ZombieException.address != 0)
{
writer->beginObject(writer, KSCrashField_LastDeallocedNSException);
{
writer->addUIntegerElement(writer, KSCrashField_Address, monitorContext->ZombieException.address);
writer->addStringElement(writer, KSCrashField_Name, monitorContext->ZombieException.name);
writer->addStringElement(writer, KSCrashField_Reason, monitorContext->ZombieException.reason);
writeAddressReferencedByString(writer, KSCrashField_ReferencedObject, monitorContext->ZombieException.reason);
}
writer->endContainer(writer);
}
}
writer->endContainer(writer);
}
|
/** Write information about this process.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*/
|
Write information about this process.
@param writer The writer.
@param key The object key, if needed.
|
writeReportInfo
|
static void writeReportInfo(const KSCrashReportWriter* const writer,
const char* const key,
const char* const type,
const char* const reportID,
const char* const processName)
{
writer->beginObject(writer, key);
{
writer->addStringElement(writer, KSCrashField_Version, KSCRASH_REPORT_VERSION);
writer->addStringElement(writer, KSCrashField_ID, reportID);
writer->addStringElement(writer, KSCrashField_ProcessName, processName);
writer->addIntegerElement(writer, KSCrashField_Timestamp, time(NULL));
writer->addStringElement(writer, KSCrashField_Type, type);
}
writer->endContainer(writer);
}
|
/** Write basic report information.
*
* @param writer The writer.
*
* @param key The object key, if needed.
*
* @param type The report type.
*
* @param reportID The report ID.
*/
|
Write basic report information.
@param writer The writer.
@param key The object key, if needed.
@param type The report type.
@param reportID The report ID.
|
prepareReportWriter
|
static void prepareReportWriter(KSCrashReportWriter* const writer, KSJSONEncodeContext* const context)
{
writer->addBooleanElement = addBooleanElement;
writer->addFloatingPointElement = addFloatingPointElement;
writer->addIntegerElement = addIntegerElement;
writer->addUIntegerElement = addUIntegerElement;
writer->addStringElement = addStringElement;
writer->addTextFileElement = addTextFileElement;
writer->addTextFileLinesElement = addTextLinesFromFile;
writer->addJSONFileElement = addJSONElementFromFile;
writer->addDataElement = addDataElement;
writer->beginDataElement = beginDataElement;
writer->appendDataElement = appendDataElement;
writer->endDataElement = endDataElement;
writer->addUUIDElement = addUUIDElement;
writer->addJSONElement = addJSONElement;
writer->beginObject = beginObject;
writer->beginArray = beginArray;
writer->endContainer = endContainer;
writer->context = context;
}
|
/** Prepare a report writer for use.
*
* @oaram writer The writer to prepare.
*
* @param context JSON writer contextual information.
*/
|
Prepare a report writer for use.
@oaram writer The writer to prepare.
@param context JSON writer contextual information.
|
onUserDump
|
static void onUserDump(struct KSCrash_MonitorContext* monitorContext, const char* dumpFilePath)
{
KSLOG_DEBUG("UserDump");
monitorContext->consoleLogPath = g_shouldAddConsoleLogToReport ? g_consoleLogPath : NULL;
if (g_customShortVersion != NULL && g_customFullVersion != NULL) {
monitorContext->UserDefinedVersion.bundleShortVersion = g_customShortVersion;
monitorContext->UserDefinedVersion.bundleVersion = g_customFullVersion;
} else {
monitorContext->UserDefinedVersion.bundleShortVersion = "unknown";
monitorContext->UserDefinedVersion.bundleVersion = "unknown";
}
if(monitorContext->crashedDuringCrashHandling)
{
kscrashreport_writeRecrashReport(monitorContext, dumpFilePath);
}
else
{
kscrashreport_writeStandardReport(monitorContext, dumpFilePath);
}
}
|
/** Called when a user dump occurs.
*
* This function gets paseed as a callback to a user dump
*/
|
Called when a user dump occurs.
This function gets paseed as a callback to a user dump
|
addJSONData
|
static int addJSONData(const char* const data, const int length, void* const userData)
{
const int fd = *((int*)userData);
const bool success = ksfu_writeBytesToFD(fd, data, length);
return success ? KSJSON_OK : KSJSON_ERROR_CANNOT_ADD_DATA;
}
|
/** Callback for adding JSON data.
*/
|
Callback for adding JSON data.
|
ksdebug_isBeingTraced
|
bool ksdebug_isBeingTraced(void)
{
struct kinfo_proc procInfo;
size_t structSize = sizeof(procInfo);
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};
if(sysctl(mib, sizeof(mib)/sizeof(*mib), &procInfo, &structSize, NULL, 0) != 0)
{
KSLOG_ERROR("sysctl: %s", strerror(errno));
return false;
}
return (procInfo.kp_proc.p_flag & P_TRACED) != 0;
}
|
/** Check if the current process is being traced or not.
*
* @return true if we're being traced.
*/
|
Check if the current process is being traced or not.
@return true if we're being traced.
|
getClassDataFromTaggedPointer
|
static const ClassData* getClassDataFromTaggedPointer(const void* const object)
{
int slot = getTaggedSlot(object);
return &g_taggedClassData[slot];
}
|
/** Get class data for a tagged pointer.
*
* @param object The tagged pointer.
* @return The class data.
*/
|
Get class data for a tagged pointer.
@param object The tagged pointer. @return The class data.
|
isTaggedPointerNSNumber
|
static bool isTaggedPointerNSNumber(const void* const object)
{
return getTaggedSlot(object) == OBJC_TAG_NSNumber;
}
|
/** Check if a tagged pointer is a number.
*
* @param object The object to query.
* @return true if the tagged pointer is an NSNumber.
*/
|
Check if a tagged pointer is a number.
@param object The object to query. @return true if the tagged pointer is an NSNumber.
|
isTaggedPointerNSString
|
static bool isTaggedPointerNSString(const void* const object)
{
return getTaggedSlot(object) == OBJC_TAG_NSString;
}
|
/** Check if a tagged pointer is a string.
*
* @param object The object to query.
* @return true if the tagged pointer is an NSString.
*/
|
Check if a tagged pointer is a string.
@param object The object to query. @return true if the tagged pointer is an NSString.
|
isTaggedPointerNSDate
|
static bool isTaggedPointerNSDate(const void* const object)
{
return getTaggedSlot(object) == OBJC_TAG_NSDate;
}
|
/** Check if a tagged pointer is a date.
*
* @param object The object to query.
* @return true if the tagged pointer is an NSDate.
*/
|
Check if a tagged pointer is a date.
@param object The object to query. @return true if the tagged pointer is an NSDate.
|
extractTaggedNSNumber
|
static int64_t extractTaggedNSNumber(const void* const object)
{
intptr_t signedPointer = (intptr_t)object;
#if SUPPORT_TAGGED_POINTERS
intptr_t value = (signedPointer << TAG_PAYLOAD_LSHIFT) >> TAG_PAYLOAD_RSHIFT;
#else
intptr_t value = signedPointer & 0;
#endif
// The lower 4 bits encode type information so shift them out.
return (int64_t)(value >> 4);
}
|
/** Extract an integer from a tagged NSNumber.
*
* @param object The NSNumber object (must be a tagged pointer).
* @return The integer value.
*/
|
Extract an integer from a tagged NSNumber.
@param object The NSNumber object (must be a tagged pointer). @return The integer value.
|
extractTaggedNSDate
|
static CFAbsoluteTime extractTaggedNSDate(const void* const object)
{
uintptr_t payload = getTaggedPayload(object);
// Payload is a 60-bit float. Fortunately we can just cast across from
// an integer pointer after shifting out the upper 4 bits.
payload <<= 4;
CFAbsoluteTime value = *((CFAbsoluteTime*)&payload);
return value;
}
|
/** Extract a tagged NSDate's time value as an absolute time.
*
* @param object The NSDate object (must be a tagged pointer).
* @return The date's absolute time.
*/
|
Extract a tagged NSDate's time value as an absolute time.
@param object The NSDate object (must be a tagged pointer). @return The date's absolute time.
|
getClassData
|
static ClassData* getClassData(const void* class)
{
const char* className = getClassName(class);
for(ClassData* data = g_classData;; data++)
{
unlikely_if(data->name == NULL)
{
return data;
}
unlikely_if(class == data->class)
{
return data;
}
unlikely_if(data->class == NULL && strcmp(className, data->name) == 0)
{
data->class = class;
return data;
}
}
}
|
/** Get any special class metadata we have about the specified class.
* It will return a generic metadata object if the type is not recognized.
*
* Note: The Objective-C runtime is free to change a class address,
* so I can't just blindly store class pointers at application start
* and then compare against them later. However, comparing strings is
* slow, so I've reached a compromise. Since I'm omly using this at
* crash time, I can assume that the Objective-C environment is frozen.
* As such, I can keep a cache of discovered classes. If, however, this
* library is used outside of a frozen environment, caching will be
* unreliable.
*
* @param class The class to examine.
*
* @return The associated class data.
*/
|
Get any special class metadata we have about the specified class. It will return a generic metadata object if the type is not recognized.
Note: The Objective-C runtime is free to change a class address, so I can't just blindly store class pointers at application start and then compare against them later. However, comparing strings is slow, so I've reached a compromise. Since I'm omly using this at crash time, I can assume that the Objective-C environment is frozen. As such, I can keep a cache of discovered classes. If, however, this library is used outside of a frozen environment, caching will be unreliable.
@param class The class to examine.
@return The associated class data.
|
addEscapedString
|
static int addEscapedString(KSJSONEncodeContext* const context,
const char* restrict const string,
int length)
{
int result = KSJSON_OK;
// Keep adding portions until the whole string has been processed.
int offset = 0;
while(offset < length)
{
int toAdd = length - offset;
unlikely_if(toAdd > KSJSONCODEC_WorkBufferSize / 2)
{
toAdd = KSJSONCODEC_WorkBufferSize / 2;
}
result = appendEscapedString(context, string + offset, toAdd);
unlikely_if(result != KSJSON_OK)
{
break;
}
offset += toAdd;
}
return result;
}
|
/** Escape a string for use with JSON and send to data handler.
*
* @param context The JSON context.
*
* @param string The string to escape and write.
*
* @param length The length of the string.
*
* @return KSJSON_OK if the data was handled successfully.
*/
|
Escape a string for use with JSON and send to data handler.
@param context The JSON context.
@param string The string to escape and write.
@param length The length of the string.
@return KSJSON_OK if the data was handled successfully.
|
addQuotedEscapedString
|
static int addQuotedEscapedString(KSJSONEncodeContext* const context,
const char* restrict const string,
int length)
{
int result;
unlikely_if((result = addJSONData(context, "\"", 1)) != KSJSON_OK)
{
return result;
}
result = addEscapedString(context, string, length);
// Always close string, even if we failed to write its content
int closeResult = addJSONData(context, "\"", 1);
return result || closeResult;
}
|
/** Escape and quote a string for use with JSON and send to data handler.
*
* @param context The JSON context.
*
* @param string The string to escape and write.
*
* @param length The length of the string.
*
* @return KSJSON_OK if the data was handled successfully.
*/
|
Escape and quote a string for use with JSON and send to data handler.
@param context The JSON context.
@param string The string to escape and write.
@param length The length of the string.
@return KSJSON_OK if the data was handled successfully.
|
isFPChar
|
static inline bool isFPChar(char ch)
{
switch(ch)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '.': case 'e': case 'E': case '+': case '-':
return true;
default:
return false;
}
}
|
/** Check if a character is valid for representing part of a floating point
* number.
*
* @param ch The character to test.
*
* @return true if the character is valid for floating point.
*/
|
Check if a character is valid for representing part of a floating point number.
@param ch The character to test.
@return true if the character is valid for floating point.
|
firstCmdAfterHeader
|
static uintptr_t firstCmdAfterHeader(const struct mach_header* const header)
{
switch(header->magic)
{
case MH_MAGIC:
case MH_CIGAM:
return (uintptr_t)(header + 1);
case MH_MAGIC_64:
case MH_CIGAM_64:
return (uintptr_t)(((struct mach_header_64*)header) + 1);
default:
// Header is corrupt
return 0;
}
}
|
/** Get the address of the first command following a header (which will be of
* type struct load_command).
*
* @param header The header to get commands for.
*
* @return The address of the first command, or NULL if none was found (which
* should not happen unless the header or image is corrupt).
*/
|
Get the address of the first command following a header (which will be of type struct load_command).
@param header The header to get commands for.
@return The address of the first command, or NULL if none was found (which should not happen unless the header or image is corrupt).
|
xh_elf_hash
|
static uint32_t xh_elf_hash(const uint8_t *name)
{
uint32_t h = 0, g;
while (*name) {
h = (h << 4) + *name++;
g = h & 0xf0000000;
h ^= g;
h ^= g >> 24;
}
return h;
}
|
/*ELF hash func*/
|
ELF hash func
|
xh_elf_gnu_hash
|
static uint32_t xh_elf_gnu_hash(const uint8_t *name)
{
uint32_t h = 5381;
while(*name != 0)
{
h += (h << 5) + *name++;
}
return h;
}
|
/*GNU hash func*/
|
GNU hash func
|
sqlite3Update
|
void sqlite3Update(
Parse *pParse, /* The parser context */
SrcList *pTabList, /* The table in which we should change things */
ExprList *pChanges, /* Things to be changed */
Expr *pWhere, /* The WHERE clause. May be null */
int onError, /* How to handle constraint errors */
Expr *pLimit,
Expr *pOffset
){
Update *updateObj = sqlite3UpdateNew(pTabList, pChanges, pWhere, onError, pLimit, pOffset);
ParsedResultItem item;
item.sqltype = SQLTYPE_UPDATE;
item.result.updateObj = updateObj;
sqlite3ParsedResultArrayAppend(&pParse->parsed, &item);
}
|
/*
** Process an UPDATE statement.
**
** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL;
** \_______/ \________/ \______/ \________________/
* onError pTabList pChanges pWhere
*/
|
Process an UPDATE statement.
UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL; \_______/ \________/ \______/ \________________/ onError pTabList pChanges pWhere
|
sqlite3ExprAffinity
|
char sqlite3ExprAffinity(Expr *pExpr){
int op = pExpr->op;
if( op==TK_AS ){
return sqlite3ExprAffinity(pExpr->pLeft);
}
if( op==TK_SELECT ){
return sqlite3ExprAffinity(pExpr->pSelect->pEList->a[0].pExpr);
}
#ifndef SQLITE_OMIT_CAST
if( op==TK_CAST ){
return sqlite3AffinityType(&pExpr->token);
}
#endif
return pExpr->affinity;
}
|
/*
** Return the 'affinity' of the expression pExpr if any.
**
** If pExpr is a column, a reference to a column via an 'AS' alias,
** or a sub-select with a column as the return value, then the
** affinity of that column is returned. Otherwise, 0x00 is returned,
** indicating no affinity for the expression.
**
** i.e. the WHERE clause expresssions in the following statements all
** have an affinity:
**
** CREATE TABLE t1(a);
** SELECT * FROM t1 WHERE a;
** SELECT a AS b FROM t1 WHERE b;
** SELECT * FROM t1 WHERE (select a from t1);
*/
|
Return the 'affinity' of the expression pExpr if any.
If pExpr is a column, a reference to a column via an 'AS' alias, or a sub-select with a column as the return value, then the affinity of that column is returned. Otherwise, 0x00 is returned, indicating no affinity for the expression.
i.e. the WHERE clause expresssions in the following statements all have an affinity:
CREATE TABLE t1(a); SELECT * FROM t1 WHERE a; SELECT a AS b FROM t1 WHERE b; SELECT * FROM t1 WHERE (select a from t1);
|
sqlite3CompareAffinity
|
char sqlite3CompareAffinity(Expr *pExpr, char aff2){
char aff1 = sqlite3ExprAffinity(pExpr);
if( aff1 && aff2 ){
/* Both sides of the comparison are columns. If one has numeric
** affinity, use that. Otherwise use no affinity.
*/
if( sqlite3IsNumericAffinity(aff1) || sqlite3IsNumericAffinity(aff2) ){
return SQLITE_AFF_NUMERIC;
}else{
return SQLITE_AFF_NONE;
}
}else if( !aff1 && !aff2 ){
/* Neither side of the comparison is a column. Compare the
** results directly.
*/
return SQLITE_AFF_NONE;
}else{
/* One side is a column, the other is not. Use the columns affinity. */
assert( aff1==0 || aff2==0 );
return (aff1 + aff2);
}
}
|
/*
** pExpr is an operand of a comparison operator. aff2 is the
** type affinity of the other operand. This routine returns the
** type affinity that should be used for the comparison operator.
*/
|
pExpr is an operand of a comparison operator. aff2 is the type affinity of the other operand. This routine returns the type affinity that should be used for the comparison operator.
|
sqlite3RegisterExpr
|
Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){
/* Vdbe *v = pParse->pVdbe; */
/* Expr *p; */
/* int depth; */
/* if( pParse->nested==0 ){ */
/* sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken); */
/* return 0; */
/* } */
/* if( v==0 ) return 0; */
/* p = sqlite3Expr(TK_REGISTER, 0, 0, pToken); */
/* if( p==0 ){ */
/* return 0; /1* Malloc failed *1/ */
/* } */
/* depth = atoi((char*)&pToken->z[1]); */
/* p->iTable = pParse->nMem++; */
/* sqlite3VdbeAddOp(v, OP_Dup, depth, 0); */
/* sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1); */
/* return p; */
}
|
/*
** When doing a nested parse, you can include terms in an expression
** that look like this: #0 #1 #2 ... These terms refer to elements
** on the stack. "#0" means the top of the stack.
** "#1" means the next down on the stack. And so forth.
**
** This routine is called by the parser to deal with on of those terms.
** It immediately generates code to store the value in a memory location.
** The returns an expression that will code to extract the value from
** that memory location as needed.
*/
|
When doing a nested parse, you can include terms in an expression that look like this: #0 #1 #2 ... These terms refer to elements on the stack. "#0" means the top of the stack. "#1" means the next down on the stack. And so forth.
This routine is called by the parser to deal with on of those terms. It immediately generates code to store the value in a memory location. The returns an expression that will code to extract the value from that memory location as needed.
|
sqlite3ExprAnd
|
Expr *sqlite3ExprAnd(Expr *pLeft, Expr *pRight){
if( pLeft==0 ){
return pRight;
}else if( pRight==0 ){
return pLeft;
}else{
return sqlite3Expr(TK_AND, pLeft, pRight, 0);
}
}
|
/*
** Join two expressions using an AND operator. If either expression is
** NULL, then just return the other expression.
*/
|
Join two expressions using an AND operator. If either expression is NULL, then just return the other expression.
|
sqlite3ExprSpan
|
void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
assert( pRight!=0 );
assert( pLeft!=0 );
if( !sqlite3MallocFailed() && pRight->z && pLeft->z ){
assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 );
if( pLeft->dyn==0 && pRight->dyn==0 ){
pExpr->span.z = pLeft->z;
pExpr->span.n = pRight->n + (pRight->z - pLeft->z);
}else{
pExpr->span.z = 0;
}
}
}
|
/*
** Set the Expr.span field of the given expression to span all
** text between the two given tokens.
*/
|
Set the Expr.span field of the given expression to span all text between the two given tokens.
|
sqlite3ExprFunction
|
Expr *sqlite3ExprFunction(ExprList *pList, Token *pToken){
Expr *pNew;
assert( pToken );
pNew = sqliteMalloc( sizeof(Expr) );
if( pNew==0 ){
sqlite3ExprListDelete(pList); /* Avoid leaking memory when malloc fails */
return 0;
}
pNew->op = TK_FUNCTION;
pNew->pList = pList;
assert( pToken->dyn==0 );
pNew->token = *pToken;
pNew->span = pNew->token;
return pNew;
}
|
/*
** Construct a new expression node for a function with multiple
** arguments.
*/
|
Construct a new expression node for a function with multiple arguments.
|
sqlite3ExprAssignVarNumber
|
void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
/* Token *pToken; */
/* if( pExpr==0 ) return; */
/* pToken = &pExpr->token; */
/* assert( pToken->n>=1 ); */
/* assert( pToken->z!=0 ); */
/* assert( pToken->z[0]!=0 ); */
/* if( pToken->n==1 ){ */
/* /1* Wildcard of the form "?". Assign the next variable number *1/ */
/* pExpr->iTable = ++pParse->nVar; */
/* }else if( pToken->z[0]=='?' ){ */
/* /1* Wildcard of the form "?nnn". Convert "nnn" to an integer and */
/* ** use it as the variable number *1/ */
/* int i; */
/* pExpr->iTable = i = atoi((char*)&pToken->z[1]); */
/* if( i<1 || i>SQLITE_MAX_VARIABLE_NUMBER ){ */
/* sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", */
/* SQLITE_MAX_VARIABLE_NUMBER); */
/* } */
/* if( i>pParse->nVar ){ */
/* pParse->nVar = i; */
/* } */
/* }else{ */
/* /1* Wildcards of the form ":aaa" or "$aaa". Reuse the same variable */
/* ** number as the prior appearance of the same name, or if the name */
/* ** has never appeared before, reuse the same variable number */
/* *1/ */
/* int i, n; */
/* n = pToken->n; */
/* for(i=0; i<pParse->nVarExpr; i++){ */
/* Expr *pE; */
/* if( (pE = pParse->apVarExpr[i])!=0 */
/* && pE->token.n==n */
/* && memcmp(pE->token.z, pToken->z, n)==0 ){ */
/* pExpr->iTable = pE->iTable; */
/* break; */
/* } */
/* } */
/* if( i>=pParse->nVarExpr ){ */
/* pExpr->iTable = ++pParse->nVar; */
/* if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){ */
/* pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10; */
/* sqliteReallocOrFree((void**)&pParse->apVarExpr, */
/* pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) ); */
/* } */
/* if( !sqlite3MallocFailed() ){ */
/* assert( pParse->apVarExpr!=0 ); */
/* pParse->apVarExpr[pParse->nVarExpr++] = pExpr; */
/* } */
/* } */
/* } */
}
|
/*
** Assign a variable number to an expression that encodes a wildcard
** in the original SQL statement.
**
** Wildcards consisting of a single "?" are assigned the next sequential
** variable number.
**
** Wildcards of the form "?nnn" are assigned the number "nnn". We make
** sure "nnn" is not too be to avoid a denial of service attack when
** the SQL statement comes from an external source.
**
** Wildcards of the form ":aaa" or "$aaa" are assigned the same number
** as the previous instance of the same wildcard. Or if this is the first
** instance of the wildcard, the next sequenial variable number is
** assigned.
*/
|
Assign a variable number to an expression that encodes a wildcard in the original SQL statement.
Wildcards consisting of a single "?" are assigned the next sequential variable number.
Wildcards of the form "?nnn" are assigned the number "nnn". We make sure "nnn" is not too be to avoid a denial of service attack when the SQL statement comes from an external source.
Wildcards of the form ":aaa" or "$aaa" are assigned the same number as the previous instance of the same wildcard. Or if this is the first instance of the wildcard, the next sequenial variable number is assigned.
|
sqlite3ExprDelete
|
void sqlite3ExprDelete(Expr *p){
if( p==0 ) return;
if( p->span.dyn ) sqliteFree((char*)p->span.z);
if( p->token.dyn ) sqliteFree((char*)p->token.z);
sqlite3ExprDelete(p->pLeft);
sqlite3ExprDelete(p->pRight);
sqlite3ExprListDelete(p->pList);
sqlite3SelectDelete(p->pSelect);
sqliteFree(p);
}
|
/*
** Recursively delete an expression tree.
*/
|
Recursively delete an expression tree.
|
sqlite3ExprListDelete
|
void sqlite3ExprListDelete(ExprList *pList){
int i;
struct ExprList_item *pItem;
if( pList==0 ) return;
assert( pList->a!=0 || (pList->nExpr==0 && pList->nAlloc==0) );
assert( pList->nExpr<=pList->nAlloc );
for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
sqlite3ExprDelete(pItem->pExpr);
sqliteFree(pItem->zName);
}
sqliteFree(pList->a);
sqliteFree(pList);
}
|
/*
** Delete an entire expression list.
*/
|
Delete an entire expression list.
|
walkExprTree
|
static int walkExprTree(Expr *pExpr, int (*xFunc)(void*,Expr*), void *pArg){
int rc;
if( pExpr==0 ) return 0;
rc = (*xFunc)(pArg, pExpr);
if( rc==0 ){
if( walkExprTree(pExpr->pLeft, xFunc, pArg) ) return 1;
if( walkExprTree(pExpr->pRight, xFunc, pArg) ) return 1;
if( walkExprList(pExpr->pList, xFunc, pArg) ) return 1;
}
return rc>1;
}
|
/*
** Walk an expression tree. Call xFunc for each node visited.
**
** The return value from xFunc determines whether the tree walk continues.
** 0 means continue walking the tree. 1 means do not walk children
** of the current node but continue with siblings. 2 means abandon
** the tree walk completely.
**
** The return value from this routine is 1 to abandon the tree walk
** and 0 to continue.
**
** NOTICE: This routine does *not* descend into subqueries.
*/
|
Walk an expression tree. Call xFunc for each node visited.
The return value from xFunc determines whether the tree walk continues. 0 means continue walking the tree. 1 means do not walk children of the current node but continue with siblings. 2 means abandon the tree walk completely.
The return value from this routine is 1 to abandon the tree walk and 0 to continue.
NOTICE: This routine does *not* descend into subqueries.
|
walkExprList
|
static int walkExprList(ExprList *p, int (*xFunc)(void *, Expr*), void *pArg){
int i;
struct ExprList_item *pItem;
if( !p ) return 0;
for(i=p->nExpr, pItem=p->a; i>0; i--, pItem++){
if( walkExprTree(pItem->pExpr, xFunc, pArg) ) return 1;
}
return 0;
}
|
/*
** Call walkExprTree() for every expression in list p.
*/
|
Call walkExprTree() for every expression in list p.
|
exprNodeIsConstant
|
static int exprNodeIsConstant(void *pArg, Expr *pExpr){
switch( pExpr->op ){
/* Consider functions to be constant if all their arguments are constant
** and *pArg==2 */
case TK_FUNCTION:
if( *((int*)pArg)==2 ) return 0;
/* Fall through */
case TK_ID:
case TK_COLUMN:
case TK_DOT:
case TK_AGG_FUNCTION:
case TK_AGG_COLUMN:
#ifndef SQLITE_OMIT_SUBQUERY
case TK_SELECT:
case TK_EXISTS:
#endif
*((int*)pArg) = 0;
return 2;
case TK_IN:
if( pExpr->pSelect ){
*((int*)pArg) = 0;
return 2;
}
default:
return 0;
}
}
|
/*
** This routine is designed as an xFunc for walkExprTree().
**
** pArg is really a pointer to an integer. If we can tell by looking
** at pExpr that the expression that contains pExpr is not a constant
** expression, then set *pArg to 0 and return 2 to abandon the tree walk.
** If pExpr does does not disqualify the expression from being a constant
** then do nothing.
**
** After walking the whole tree, if no nodes are found that disqualify
** the expression as constant, then we assume the whole expression
** is constant. See sqlite3ExprIsConstant() for additional information.
*/
|
This routine is designed as an xFunc for walkExprTree().
pArg is really a pointer to an integer. If we can tell by looking at pExpr that the expression that contains pExpr is not a constant expression, then set *pArg to 0 and return 2 to abandon the tree walk. If pExpr does does not disqualify the expression from being a constant then do nothing.
After walking the whole tree, if no nodes are found that disqualify the expression as constant, then we assume the whole expression is constant. See sqlite3ExprIsConstant() for additional information.
|
sqlite3ExprIsConstant
|
int sqlite3ExprIsConstant(Expr *p){
int isConst = 1;
walkExprTree(p, exprNodeIsConstant, &isConst);
return isConst;
}
|
/*
** Walk an expression tree. Return 1 if the expression is constant
** and 0 if it involves variables or function calls.
**
** For the purposes of this function, a double-quoted string (ex: "abc")
** is considered a variable but a single-quoted string (ex: 'abc') is
** a constant.
*/
|
Walk an expression tree. Return 1 if the expression is constant and 0 if it involves variables or function calls.
For the purposes of this function, a double-quoted string (ex: "abc") is considered a variable but a single-quoted string (ex: 'abc') is a constant.
|
sqlite3ExprIsConstantOrFunction
|
int sqlite3ExprIsConstantOrFunction(Expr *p){
int isConst = 2;
walkExprTree(p, exprNodeIsConstant, &isConst);
return isConst!=0;
}
|
/*
** Walk an expression tree. Return 1 if the expression is constant
** or a function call with constant arguments. Return and 0 if there
** are any variables.
**
** For the purposes of this function, a double-quoted string (ex: "abc")
** is considered a variable but a single-quoted string (ex: 'abc') is
** a constant.
*/
|
Walk an expression tree. Return 1 if the expression is constant or a function call with constant arguments. Return and 0 if there are any variables.
For the purposes of this function, a double-quoted string (ex: "abc") is considered a variable but a single-quoted string (ex: 'abc') is a constant.
|
sqlite3IsRowid
|
int sqlite3IsRowid(const char *z){
if( sqlite3StrICmp(z, "_ROWID_")==0 ) return 1;
if( sqlite3StrICmp(z, "ROWID")==0 ) return 1;
if( sqlite3StrICmp(z, "OID")==0 ) return 1;
return 0;
}
|
/*
** Return TRUE if the given string is a row-id column name.
*/
|
Return TRUE if the given string is a row-id column name.
|
addAggInfoColumn
|
static int addAggInfoColumn(AggInfo *pInfo){
int i;
i = sqlite3ArrayAllocate((void**)&pInfo->aCol, sizeof(pInfo->aCol[0]), 3);
if( i<0 ){
return -1;
}
return i;
}
|
/*
** Add a new element to the pAggInfo->aCol[] array. Return the index of
** the new element. Return a negative number if malloc fails.
*/
|
Add a new element to the pAggInfo->aCol[] array. Return the index of the new element. Return a negative number if malloc fails.
|
addAggInfoFunc
|
static int addAggInfoFunc(AggInfo *pInfo){
int i;
i = sqlite3ArrayAllocate((void**)&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2);
if( i<0 ){
return -1;
}
return i;
}
|
/*
** Add a new element to the pAggInfo->aFunc[] array. Return the index of
** the new element. Return a negative number if malloc fails.
*/
|
Add a new element to the pAggInfo->aFunc[] array. Return the index of the new element. Return a negative number if malloc fails.
|
sqlite3ParserTokenName
|
const char *sqlite3ParserTokenName(int tokenType){
#ifndef NDEBUG
if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
return yyTokenName[tokenType];
}else{
return "Unknown";
}
#else
return "";
#endif
}
|
/*
** This function returns the symbolic name associated with a token
** value.
*/
|
This function returns the symbolic name associated with a token value.
|
sqlite3ParserAlloc
|
void *sqlite3ParserAlloc(void *(*mallocProc)(size_t)){
yyParser *pParser;
pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
if( pParser ){
pParser->yyidx = -1;
}
return pParser;
}
|
/*
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
**
** Inputs:
** A pointer to the function used to allocate memory.
**
** Outputs:
** A pointer to a parser. This pointer is used in subsequent calls
** to sqlite3Parser and sqlite3ParserFree.
*/
|
This function allocates a new parser. The only argument is a pointer to a function which works like malloc.
Inputs: A pointer to the function used to allocate memory.
Outputs: A pointer to a parser. This pointer is used in subsequent calls to sqlite3Parser and sqlite3ParserFree.
|
yy_pop_parser_stack
|
static int yy_pop_parser_stack(yyParser *pParser){
YYCODETYPE yymajor;
yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
if( pParser->yyidx<0 ) return 0;
#ifndef NDEBUG
if( yyTraceFILE && pParser->yyidx>=0 ){
fprintf(yyTraceFILE,"%sPopping %s\n",
yyTracePrompt,
yyTokenName[yytos->major]);
}
#endif
yymajor = yytos->major;
yy_destructor( yymajor, &yytos->minor);
pParser->yyidx--;
return yymajor;
}
|
/*
** Pop the parser's stack once.
**
** If there is a destructor routine associated with the token which
** is popped from the stack, then call it.
**
** Return the major token number for the symbol popped.
*/
|
Pop the parser's stack once.
If there is a destructor routine associated with the token which is popped from the stack, then call it.
Return the major token number for the symbol popped.
|
sqlite3ParserFree
|
void sqlite3ParserFree(
void *p, /* The parser to be deleted */
void (*freeProc)(void*) /* Function used to reclaim memory */
){
yyParser *pParser = (yyParser*)p;
if( pParser==0 ) return;
while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
(*freeProc)((void*)pParser);
}
|
/*
** Deallocate and destroy a parser. Destructors are all called for
** all stack elements before shutting the parser down.
**
** Inputs:
** <ul>
** <li> A pointer to the parser. This should be a pointer
** obtained from sqlite3ParserAlloc.
** <li> A pointer to a function used to reclaim memory obtained
** from malloc.
** </ul>
*/
|
Deallocate and destroy a parser. Destructors are all called for all stack elements before shutting the parser down.
Inputs: <ul> <li> A pointer to the parser. This should be a pointer obtained from sqlite3ParserAlloc. <li> A pointer to a function used to reclaim memory obtained from malloc. </ul>
|
yy_find_reduce_action
|
static int yy_find_reduce_action(
int stateno, /* Current state number */
int iLookAhead /* The look-ahead token */
){
int i;
/* int stateno = pParser->yystack[pParser->yyidx].stateno; */
if( stateno>YY_REDUCE_MAX ||
(i = yy_reduce_ofst[stateno])==YY_REDUCE_USE_DFLT ){
return yy_default[stateno];
}
if( iLookAhead==YYNOCODE ){
return YY_NO_ACTION;
}
i += iLookAhead;
if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
return yy_default[stateno];
}else{
return yy_action[i];
}
}
|
/*
** Find the appropriate action for a parser given the non-terminal
** look-ahead token iLookAhead.
**
** If the look-ahead token is YYNOCODE, then check to see if the action is
** independent of the look-ahead. If it is, return the action, otherwise
** return YY_NO_ACTION.
*/
|
Find the appropriate action for a parser given the non-terminal look-ahead token iLookAhead.
If the look-ahead token is YYNOCODE, then check to see if the action is independent of the look-ahead. If it is, return the action, otherwise return YY_NO_ACTION.
|
yy_parse_failed
|
static void yy_parse_failed(
yyParser *yypParser /* The parser */
){
sqlite3ParserARG_FETCH;
#ifndef NDEBUG
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
}
#endif
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
/* Here code is inserted which will be executed whenever the
** parser fails */
sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
|
/*
** The following code executes when the parse fails
*/
|
The following code executes when the parse fails
|
yy_syntax_error
|
static void yy_syntax_error(
yyParser *yypParser, /* The parser */
int yymajor, /* The major type of the error token */
YYMINORTYPE yyminor /* The minor type of the error token */
){
sqlite3ParserARG_FETCH;
#define TOKEN (yyminor.yy0)
#line 34 "parse.y"
if( pParse->zErrMsg==0 ){
if( TOKEN.z[0] ){
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
}else{
sqlite3ErrorMsg(pParse, "incomplete SQL statement");
}
}
#line 2784 "parse.c"
sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
|
/*
** The following code executes when a syntax error first occurs.
*/
|
The following code executes when a syntax error first occurs.
|
yy_accept
|
static void yy_accept(
yyParser *yypParser /* The parser */
){
sqlite3ParserARG_FETCH;
#ifndef NDEBUG
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
}
#endif
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
/* Here code is inserted which will be executed whenever the
** parser accepts */
sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
|
/*
** The following is executed when the parser accepts
*/
|
The following is executed when the parser accepts
|
threadLockingTest
|
static void *threadLockingTest(void *pArg){
struct threadTestData *pData = (struct threadTestData*)pArg;
pData->result = fcntl(pData->fd, F_SETLK, &pData->lock);
return pArg;
}
|
/*
** The testThreadLockingBehavior() routine launches two separate
** threads on this routine. This routine attempts to lock a file
** descriptor then returns. The success or failure of that attempt
** allows the testThreadLockingBehavior() procedure to determine
** whether or not threads can override each others locks.
*/
|
The testThreadLockingBehavior() routine launches two separate threads on this routine. This routine attempts to lock a file descriptor then returns. The success or failure of that attempt allows the testThreadLockingBehavior() procedure to determine whether or not threads can override each others locks.
|
locktypeName
|
static const char *locktypeName(int locktype){
switch( locktype ){
case NO_LOCK: return "NONE";
case SHARED_LOCK: return "SHARED";
case RESERVED_LOCK: return "RESERVED";
case PENDING_LOCK: return "PENDING";
case EXCLUSIVE_LOCK: return "EXCLUSIVE";
}
return "ERROR";
}
|
/*
** Helper function for printing out trace information from debugging
** binaries. This returns the string represetation of the supplied
** integer lock-type.
*/
|
Helper function for printing out trace information from debugging binaries. This returns the string represetation of the supplied integer lock-type.
|
sqlite3UnixDelete
|
int sqlite3UnixDelete(const char *zFilename){
unlink(zFilename);
return SQLITE_OK;
}
|
/*
** Delete the named file
*/
|
Delete the named file
|
sqlite3UnixFileExists
|
int sqlite3UnixFileExists(const char *zFilename){
return access(zFilename, 0)==0;
}
|
/*
** Return TRUE if the named file exists.
*/
|
Return TRUE if the named file exists.
|
unixOpenDirectory
|
static int unixOpenDirectory(
OsFile *id,
const char *zDirname
){
unixFile *pFile = (unixFile*)id;
if( pFile==0 ){
/* Do not open the directory if the corresponding file is not already
** open. */
return SQLITE_CANTOPEN;
}
SET_THREADID(pFile);
assert( pFile->dirfd<0 );
pFile->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0);
if( pFile->dirfd<0 ){
return SQLITE_CANTOPEN;
}
TRACE3("OPENDIR %-3d %s\n", pFile->dirfd, zDirname);
return SQLITE_OK;
}
|
/*
** Attempt to open a file descriptor for the directory that contains a
** file. This file descriptor can be used to fsync() the directory
** in order to make sure the creation of a new file is actually written
** to disk.
**
** This routine is only meaningful for Unix. It is a no-op under
** windows since windows does not support hard links.
**
** On success, a handle for a previously open file at *id is
** updated with the new directory file descriptor and SQLITE_OK is
** returned.
**
** On failure, the function returns SQLITE_CANTOPEN and leaves
** *id unchanged.
*/
|
Attempt to open a file descriptor for the directory that contains a file. This file descriptor can be used to fsync() the directory in order to make sure the creation of a new file is actually written to disk.
This routine is only meaningful for Unix. It is a no-op under windows since windows does not support hard links.
On success, a handle for a previously open file at *id is updated with the new directory file descriptor and SQLITE_OK is returned.
On failure, the function returns SQLITE_CANTOPEN and leaves *id unchanged.
|
sqlite3UnixIsDirWritable
|
int sqlite3UnixIsDirWritable(char *zBuf){
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
struct stat buf;
if( zBuf==0 ) return 0;
if( zBuf[0]==0 ) return 0;
if( stat(zBuf, &buf) ) return 0;
if( !S_ISDIR(buf.st_mode) ) return 0;
if( access(zBuf, 07) ) return 0;
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
return 1;
}
|
/*
** Check that a given pathname is a directory and is writable
**
*/
|
Check that a given pathname is a directory and is writable
|
seekAndRead
|
static int seekAndRead(unixFile *id, void *pBuf, int cnt){
int got;
#ifdef USE_PREAD
got = pread(id->h, pBuf, cnt, id->offset);
#else
lseek(id->h, id->offset, SEEK_SET);
got = read(id->h, pBuf, cnt);
#endif
if( got>0 ){
id->offset += got;
}
return got;
}
|
/*
** Seek to the offset in id->offset then read cnt bytes into pBuf.
** Return the number of bytes actually read. Update the offset.
*/
|
Seek to the offset in id->offset then read cnt bytes into pBuf. Return the number of bytes actually read. Update the offset.
|
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 42