write_u32(buf + CHUNK_TV_TV_SEC_OFFSET, afhi->chunk_tv.tv_sec);
write_u32(buf + CHUNK_TV_TV_USEC_OFFSET, afhi->chunk_tv.tv_usec);
p = buf + AFHI_INFO_STRING_OFFSET;
- /* The sprintf's below are OK as our caller made sure that buf is large enough */
+ /*
+ * The below sprintf(3) calls are OK because our caller already made
+ * sure that buf is large enough.
+ */
p += sprintf(p, "%s", afhi->techinfo) + 1;
p += sprintf(p, "%s", afhi->tags.artist) + 1;
p += sprintf(p, "%s", afhi->tags.title) + 1;
sprintf(p, "%s", afhi->tags.comment);
}
+/* does not load the chunk table */
static void load_afhi(const char *buf, struct afh_info *afhi)
{
afhi->seconds_total = read_u32(buf + AFHI_SECONDS_TOTAL_OFFSET);
* \param row Pointer to a row in the audio file table.
* \param path Result pointer.
*
- * The result is a pointer to mmapped data. The caller must not attempt
+ * The result is a pointer to memory-mapped data. The caller must not attempt
* to free it.
*
* \return Standard.
* \param afhi Result pointer.
*
* \return The return value of the underlying call to osl_get_object().
+ *
+ * After the call the members of the afhi structure point to mapped memory
+ * which is owned by the osl table, Hence the caller must not attempt to free
+ * this memory by calling \ref clear_afhi().
*/
int get_afhi_of_row(const struct osl_row *row, struct afh_info *afhi)
{
/*
* If the given time is more than six month away from the current time,
* we print only the year. The additional space character in the format
- * string below makes the formated date align nicely with dates that
+ * string below makes the formatted date align nicely with dates that
* contain the time (those written by the above strftime() statement).
*/
if (!strftime(buf, size, "%b %e %Y", tm))
return ret;
}
+static int ls_hash_compare(const void *a, const void *b)
+{
+ struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b;
+ return memcmp(d1->hash, d2->hash, HASH_SIZE);
+}
+
static int ls_audio_format_compare(const void *a, const void *b)
{
struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b;
compar = ls_duration_compare; break;
case LS_SORT_BY_AUDIO_FORMAT:
compar = ls_audio_format_compare; break;
+ case LS_SORT_BY_HASH:
+ compar = ls_hash_compare; break;
default:
return -E_BAD_SORT;
}
return ret;
}
-/* TODO: flags -h (sort by hash) */
static int com_ls(struct command_context *cc, struct lls_parse_result *lpr)
{
const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LS);
opts->sorting = LS_SORT_BY_DURATION;
else if (!strcmp(val, "a") || !strcmp(val, "audio-format"))
opts->sorting = LS_SORT_BY_AUDIO_FORMAT;
+ else if (!strcmp(val, "h") || !strcmp(val, "hash"))
+ opts->sorting = LS_SORT_BY_HASH;
else {
ret = -E_AFT_SYNTAX;
goto out;