static void _hadoofus_file_status_to_libhdfs(const char *dfs_uri, const char *path, struct hdfs_object *fs, hdfsFileInfo *fi_out) { struct hdfs_file_status *f = &fs->ob_val._file_status; fi_out->mKind = f->_directory? kObjectKindDirectory : kObjectKindFile; fi_out->mName = malloc(strlen(dfs_uri) + strlen(path) + 1 + strlen(f->_file) + 1); assert(fi_out->mName); strcpy(fi_out->mName, dfs_uri); strcat(fi_out->mName, path); if (strcmp(path, "/")) strcat(fi_out->mName, "/"); strcat(fi_out->mName, f->_file); fi_out->mLastMod = f->_mtime / 1000; /* ms -> s */ fi_out->mSize = f->_size; fi_out->mReplication = f->_replication; fi_out->mBlockSize = f->_block_size; fi_out->mOwner = _xstrdup(f->_owner); fi_out->mGroup = _xstrdup(f->_group); fi_out->mPermissions = f->_permissions | (f->_directory? S_IFDIR : S_IFREG); fi_out->mLastAccess = f->_atime / 1000; /* ms -> s */ }
char * xasprintf( const char *format, ... ) { const char error[] = "Out of memory, xasprintf failed"; va_list args; va_start( args, format ); char *str; if ( trema_vasprintf( &str, format, args ) < 0 ) { die( error ); } char *result = _xstrdup( str, error ); free( str ); va_end( args ); return result; }
char * xstrdup( const char *s ) { return _xstrdup( s, "Out of memory, xstrdup failed" ); }