mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
strdup
This commit is contained in:
parent
731f6fc322
commit
eb4573b06c
3 changed files with 21 additions and 11 deletions
|
@ -10,9 +10,10 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "proxmark3.h"
|
#include "proxmark3.h"
|
||||||
#include <limits.h>
|
|
||||||
#include <stdio.h> // for Mingw readline
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h> // for Mingw readline
|
||||||
|
#include <limits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
|
@ -27,7 +28,6 @@
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
|
|
||||||
|
|
||||||
static void showBanner(void) {
|
static void showBanner(void) {
|
||||||
g_printAndLog = PRINTANDLOG_PRINT;
|
g_printAndLog = PRINTANDLOG_PRINT;
|
||||||
|
|
||||||
|
@ -169,13 +169,16 @@ check_script:
|
||||||
// remove linebreaks
|
// remove linebreaks
|
||||||
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
|
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
|
||||||
|
|
||||||
if ((cmd = strmcopy(script_cmd_buf)) != NULL)
|
cmd = strdup(script_cmd_buf);
|
||||||
|
if (cmd != NULL)
|
||||||
printprompt = true;
|
printprompt = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If there is a script command
|
// If there is a script command
|
||||||
if (execCommand) {
|
if (execCommand) {
|
||||||
if ((cmd = strmcopy(script_cmd)) != NULL)
|
|
||||||
|
cmd = strdup(script_cmd);
|
||||||
|
if (cmd != NULL)
|
||||||
printprompt = true;
|
printprompt = true;
|
||||||
|
|
||||||
uint16_t len = strlen(script_cmd) + 1;
|
uint16_t len = strlen(script_cmd) + 1;
|
||||||
|
@ -203,7 +206,8 @@ check_script:
|
||||||
// remove linebreaks
|
// remove linebreaks
|
||||||
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
|
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
|
||||||
|
|
||||||
if ((cmd = strmcopy(script_cmd_buf)) != NULL)
|
cmd = strdup(script_cmd_buf);
|
||||||
|
if (cmd != NULL)
|
||||||
printprompt = true;
|
printprompt = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -918,11 +918,16 @@ void strcreplace(char *buf, size_t len, char from, char to) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strmcopy(const char *src) {
|
|
||||||
int len = strlen(src) + 1;
|
char *strdup(const char *src) {
|
||||||
char *dest = (char *) calloc(len, sizeof(uint8_t));
|
return strndup(src, strlen(src));
|
||||||
|
}
|
||||||
|
char *strndup(const char *src, size_t len) {
|
||||||
|
|
||||||
|
char *dest = (char *) calloc(len + 1, sizeof(uint8_t));
|
||||||
if (dest != NULL) {
|
if (dest != NULL) {
|
||||||
strncat(dest, src, len);
|
memcpy(dest, src, len);
|
||||||
|
dest[len] = '\0';
|
||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ bool str_endswith(const char *s, const char *suffix); // check for suffix in
|
||||||
void clean_ascii(unsigned char *buf, size_t len);
|
void clean_ascii(unsigned char *buf, size_t len);
|
||||||
void strcleanrn(char *buf, size_t len);
|
void strcleanrn(char *buf, size_t len);
|
||||||
void strcreplace(char *buf, size_t len, char from, char to);
|
void strcreplace(char *buf, size_t len, char from, char to);
|
||||||
char *strmcopy(const char *src);
|
char *strdup(const char *src);
|
||||||
|
char *strndup(const char *src, size_t len);
|
||||||
int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str);
|
int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue