mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
- fuse/filecache:
* add filecache_upload_patch
* allow opening files in modes other than RDONLY
- fuse/hashtbl:
* add folder_tree_upload_patch
- fuse/operations:
* allow opening files in modes other than RDONLY
* add members to private context which allow tracking of
not-yet-uploaded files and files opened for writing and
files opened in read-only mode
- mfapi/apicalls/upload_patch:
* supply x-filename and x-filesize headers
- mfapi/apicalls/upload_simple:
* do not supply the x-filehash header as it is not used by the
server
- utils/hash:
* hex characters must be lower case for the server
- utils/strings:
* clean up unused functions strdup_join, strdup_substr,
string_chomp
- utils/stringv:
* complete rewrite with different string vector implementation
97 lines
2.4 KiB
C
97 lines
2.4 KiB
C
/*
|
|
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
|
* 2014 Johannes Schauer <j.schauer@email.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2, as published by
|
|
* the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L // for getline
|
|
|
|
#include <ctype.h>
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <termios.h>
|
|
|
|
#include "strings.h"
|
|
#include "stringv.h"
|
|
|
|
char *strdup_printf(char *fmt, ...)
|
|
{
|
|
// Good for glibc 2.1 and above. Fedora5 is 2.4.
|
|
|
|
char *ret_str = NULL;
|
|
va_list ap;
|
|
int bytes_to_allocate;
|
|
|
|
va_start(ap, fmt);
|
|
bytes_to_allocate = vsnprintf(ret_str, 0, fmt, ap);
|
|
va_end(ap);
|
|
|
|
// Add one for '\0'
|
|
bytes_to_allocate++;
|
|
|
|
ret_str = (char *)malloc(bytes_to_allocate * sizeof(char));
|
|
if (ret_str == NULL) {
|
|
fprintf(stderr, "failed to allocate memory\n");
|
|
return NULL;
|
|
}
|
|
|
|
va_start(ap, fmt);
|
|
bytes_to_allocate = vsnprintf(ret_str, bytes_to_allocate, fmt, ap);
|
|
va_end(ap);
|
|
|
|
return ret_str;
|
|
}
|
|
|
|
char *string_line_from_stdin(bool hide)
|
|
{
|
|
char *line = NULL;
|
|
size_t len;
|
|
ssize_t bytes_read;
|
|
struct termios old,
|
|
new;
|
|
|
|
if (hide) {
|
|
if (tcgetattr(STDIN_FILENO, &old) != 0)
|
|
return NULL;
|
|
new = old;
|
|
new.c_lflag &= ~ECHO;
|
|
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &new) != 0)
|
|
return NULL;
|
|
}
|
|
|
|
bytes_read = getline(&line, &len, stdin);
|
|
|
|
if (hide) {
|
|
tcsetattr(STDIN_FILENO, TCSAFLUSH, &old);
|
|
}
|
|
|
|
if (bytes_read < 3) {
|
|
if (line != NULL) {
|
|
free(line);
|
|
line = NULL;
|
|
}
|
|
}
|
|
|
|
if (line[strlen(line) - 1] == '\n')
|
|
line[strlen(line) - 1] = '\0';
|
|
|
|
return line;
|
|
}
|