/* loads a file and returns a pointer to it in memory. The file contains
* a 0 byte(sentinel) after len bytes - the length of the file. */
int loadFile(const char *fileName, void **data, size_t *len)
{
/* loads a file and returns a pointer to it in memory. The file contains
* a 0 byte(sentinel) after len bytes - the length of the file. */
int loadFile(const char *fileName, void **data, size_t *len)
{
LOG_ERROR("Can't open %s", fileName);
fclose(pFile);
return ERROR_FAIL;
}
long fsize = ftell(pFile);
LOG_ERROR("Can't open %s", fileName);
fclose(pFile);
return ERROR_FAIL;
}
long fsize = ftell(pFile);
LOG_ERROR("Can't open %s", fileName);
fclose(pFile);
return ERROR_FAIL;
}
*data = malloc(*len + 1);
LOG_ERROR("Can't open %s", fileName);
fclose(pFile);
return ERROR_FAIL;
}
*data = malloc(*len + 1);
- if (fread(*data, 1, *len, pFile)!=*len)
- {
+ if (fread(*data, 1, *len, pFile) != *len) {
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "w");
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "w");
int retval = ERROR_FAIL;
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "a");
int retval = ERROR_FAIL;
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "a");
if (fwrite(CMD_ARGV[i], 1, strlen(CMD_ARGV[i]),
config_file) != strlen(CMD_ARGV[i]))
break;
if (fwrite(CMD_ARGV[i], 1, strlen(CMD_ARGV[i]),
config_file) != strlen(CMD_ARGV[i]))
break;
if (fwrite(" ", 1, 1, config_file) != 1)
break;
}
if (fwrite(" ", 1, 1, config_file) != 1)
break;
}
if ((retval == ERROR_OK) && (fwrite(((char *)data) + pos, 1, chunk, f) != chunk))
if ((retval == ERROR_OK) && (fwrite(((char *)data) + pos, 1, chunk, f) != chunk))
command_print(CMD_CTX, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]);
command_print(CMD_CTX, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]);
strcpy(fullname2, destdir);
strcat(fullname2, "/");
strcat(fullname2, entry->d_name);
strcpy(fullname2, destdir);
strcat(fullname2, "/");
strcat(fullname2, entry->d_name);
Jim_WrongNumArgs(interp, 1, argv, "ls ?dir?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "ls ?dir?");
return JIM_ERR;
}
- Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, entry->d_name, strlen(entry->d_name)));
+ Jim_ListAppendElement(interp, objPtr,
+ Jim_NewStringObj(interp, entry->d_name, strlen(entry->d_name)));
Jim_WrongNumArgs(interp, 1, argv, "peek ?address?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "peek ?address?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "poke ?address? ?value?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "poke ?address? ?value?");
return JIM_ERR;
}
/* not so pretty code to fish out ip number*/
static int ioutil_Jim_Command_ip(Jim_Interp *interp, int argc,
/* not so pretty code to fish out ip number*/
static int ioutil_Jim_Command_ip(Jim_Interp *interp, int argc,
struct ifaddrs *ifa = NULL, *ifp = NULL;
if (getifaddrs(&ifp) < 0)
struct ifaddrs *ifa = NULL, *ifp = NULL;
if (getifaddrs(&ifp) < 0)
if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0,
NI_NUMERICHOST) < 0)
if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0,
NI_NUMERICHOST) < 0)
Jim_AppendString(interp, tclOutput, ip, strlen(ip));
break;
Jim_AppendString(interp, tclOutput, ip, strlen(ip));
break;
/* not so pretty code to fish out eth0 mac address */
static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc,
/* not so pretty code to fish out eth0 mac address */
static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc,
{
if (strcmp("eth0", ifr->ifr_name) != 0)
continue;
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
{
if (strcmp("eth0", ifr->ifr_name) != 0)
continue;
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
char buffer[256];
sprintf(buffer, "%02x-%02x-%02x-%02x-%02x-%02x",
Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
char buffer[256];
sprintf(buffer, "%02x-%02x-%02x-%02x-%02x-%02x",
- ifreq.ifr_hwaddr.sa_data[0]&0xff,
- ifreq.ifr_hwaddr.sa_data[1]&0xff,
- ifreq.ifr_hwaddr.sa_data[2]&0xff,
- ifreq.ifr_hwaddr.sa_data[3]&0xff,
- ifreq.ifr_hwaddr.sa_data[4]&0xff,
- ifreq.ifr_hwaddr.sa_data[5]&0xff);
+ ifreq.ifr_hwaddr.sa_data[0]&0xff,
+ ifreq.ifr_hwaddr.sa_data[1]&0xff,
+ ifreq.ifr_hwaddr.sa_data[2]&0xff,
+ ifreq.ifr_hwaddr.sa_data[3]&0xff,
+ ifreq.ifr_hwaddr.sa_data[4]&0xff,
+ ifreq.ifr_hwaddr.sa_data[5]&0xff);
Jim_AppendString(interp, tclOutput, buffer, strlen(buffer));
Jim_AppendString(interp, tclOutput, buffer, strlen(buffer));
.handler = handle_cat_command,
.mode = COMMAND_ANY,
.help = "display text file content",
.handler = handle_cat_command,
.mode = COMMAND_ANY,
.help = "display text file content",
},
{
.name = "trunc",
.handler = handle_trunc_command,
.mode = COMMAND_ANY,
.help = "truncate a file to zero length",
},
{
.name = "trunc",
.handler = handle_trunc_command,
.mode = COMMAND_ANY,
.help = "truncate a file to zero length",
.handler = handle_append_command,
.mode = COMMAND_ANY,
.help = "append a variable number of strings to a file",
.handler = handle_append_command,
.mode = COMMAND_ANY,
.help = "append a variable number of strings to a file",