mirror of
https://github.com/fangfufu/httpdirfs.git
synced 2024-10-01 14:41:15 +02:00
modified strndupcat, added more comments
This commit is contained in:
parent
e5c77f3680
commit
b1971a7c3f
15
src/cache.c
15
src/cache.c
@ -19,8 +19,17 @@
|
|||||||
*
|
*
|
||||||
* More information regarding block size can be found at:
|
* More information regarding block size can be found at:
|
||||||
* https://wiki.vuze.com/w/Torrent_Piece_Size
|
* https://wiki.vuze.com/w/Torrent_Piece_Size
|
||||||
|
*
|
||||||
|
* Note that at the current configuration, a 16GiB file uses 128MiB of memory to
|
||||||
|
* store the bitmap, but hey, I have 16GiB on my computer!
|
||||||
*/
|
*/
|
||||||
#define DATA_BLK_SZ 131072
|
#define DATA_BLK_SZ 131072
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief the maximum length of a path
|
||||||
|
* \details This corresponds the maximum path length under Ext4. If you need
|
||||||
|
* longer path, then fuck you.
|
||||||
|
*/
|
||||||
#define MAX_PATH_LEN 4096
|
#define MAX_PATH_LEN 4096
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,9 +408,3 @@ long Data_write(const Cache *cf, long offset, long len,
|
|||||||
}
|
}
|
||||||
return byte_written;
|
return byte_written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
14
src/util.c
14
src/util.c
@ -6,9 +6,18 @@
|
|||||||
|
|
||||||
char *strndupcat(const char *a, const char *b, int n)
|
char *strndupcat(const char *a, const char *b, int n)
|
||||||
{
|
{
|
||||||
int na = strnlen(a, n/2);
|
int na = strnlen(a, n);
|
||||||
int nb = strnlen(b, n/2);
|
int nb = strnlen(b, n);
|
||||||
int nc = na + nb + 1;
|
int nc = na + nb + 1;
|
||||||
|
if (nc > n) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"strndupcat(): resulting string length exceeds maximum limit!\n");
|
||||||
|
/*
|
||||||
|
* It is better to crash the program here, then corrupting the cache
|
||||||
|
* folder
|
||||||
|
*/
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
char *c = calloc(nc, sizeof(char));
|
char *c = calloc(nc, sizeof(char));
|
||||||
if (!c) {
|
if (!c) {
|
||||||
fprintf(stderr, "strndupcat(): calloc failure!\n");
|
fprintf(stderr, "strndupcat(): calloc failure!\n");
|
||||||
@ -16,5 +25,6 @@ char *strndupcat(const char *a, const char *b, int n)
|
|||||||
}
|
}
|
||||||
strncpy(c, a, na);
|
strncpy(c, a, na);
|
||||||
strncat(c, b, nb);
|
strncat(c, b, nb);
|
||||||
|
c[nc-1] = '\0';
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
* \brief strndup with concatenation
|
* \brief strndup with concatenation
|
||||||
* \details This function concatenate string a and string b together, and put
|
* \details This function concatenate string a and string b together, and put
|
||||||
* the result in a new string.
|
* the result in a new string.
|
||||||
* \note The maximum length of string a and string b is half the length of the
|
|
||||||
* maximum length of the output string.
|
|
||||||
* \param[in] a the first string
|
* \param[in] a the first string
|
||||||
* \param[in] b the second string
|
* \param[in] b the second string
|
||||||
* \param[n] c the maximum length of the output string
|
* \param[n] c the maximum length of the output string
|
||||||
|
Loading…
Reference in New Issue
Block a user