本文整理汇总了C++中cd函数的典型用法代码示例。如果您正苦于以下问题:C++ cd函数的具体用法?C++ cd怎么用?C++ cd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Comando_Terminal_Local
int Comando_Terminal_Local(int conexao,char *param,int tipo){
int ret;
if(tipo==CD){
if(ret=cd(param)==-1) printf("Diretório inexistente ou sem acesso\n");
}
else ls(param);
if(param!=NULL) strcpy(param,"");
return;
}
示例2: popd
int popd(Stack *in){
if(in->top == -1){
return EXIT_FAILURE;
}
else{
char *temp = in->stack[in->top--];
cd(temp);
free(temp);
return EXIT_SUCCESS;
}
}
示例3: QDir
QString Paths::resourceDir(const QString& file)
{
auto resourceDir = QDir(QGuiApplication::applicationDirPath());
#ifdef Q_OS_MAC
resourceDir.cdUp();
resourceDir.cd("Resources");
#endif
return resourceDir.filePath(file);
}
示例4: TEST
TEST(CompressedMatrix, CopyConstructor)
{
CompressedMatrix<int> ci(3, 3);
ci[0][0] = 1;
ci[1][1] = 2;
ci[2][2] = 3;
CompressedMatrix<double> cd(ci);
EXPECT_EQ(ci, cd);
}
示例5: touchTest
//This tests touch and creat
//First test makes sure the mtime changes on a file that exists.
//Returns 0 if the time isnt greater than what it was before.
//Second test touches a file that doesnt exits, and therefore makes one.
//Checks the inode of the new file, and if isn't what is expected, returns zero.
//This second test checks both if touch and creat are working.
int touchTest()
{
MINODE *test_mip = running->cwd;
INODE *ip = NULL;
int ino = 0;
int old = 0;
int expected1 = 28;
strcpy(pathname, "");
cd(pathname);
test_mip = running->cwd;
printf("\n\n-------- TESTING TOUCH FUNCTION --------\n\n");
strcpy(pathname, "tiny");
ino = getino(test_mip, pathname);
test_mip = iget(dev, ino);
ip = &test_mip->INODE;
old = ip->i_mtime;
printf("tiny's current mtime = %d\n", ip->i_mtime);
printf("Testing >touch tiny\n");
strcpy(pathname, "tiny");
touch_file(pathname);
printf("tiny's new mtime = %d\n", ip->i_mtime);
if(ip->i_mtime > old)
printf("TEST PASSED!\n\n");
else
{
printf("TEST FAILED!\n\n");
return 0;
}
test_mip = running->cwd;
printf("Testing >touch newfile\n");
strcpy(pathname, "newfile");
touch_file(pathname);
strcpy(pathname, "newfile");
ino = getino(test_mip, pathname);
printf("Expected ino of newfile = %d\n", expected1);
printf("Actual ino of newfile = %d\n", ino);
if (ino != expected1)
{
printf("TEST FAILED!\n\n");
return 0;
}
printf("TEST PASSED!\n\n");
printf("\nALL TOUCH TESTS PASSED!\n\n\n");
return 1;
}
示例6: pushd
int pushd(int argc, char** argv) {
if (top==MAX_DIRECTORY_STACK) {
fprintf(stderr,"%s: cannot pushd: directory stack full\n",shellname);
return 1;
} else {
dstack[top]=getcwd(malloc(PATH_MAX),PATH_MAX); // push current directory to stack
top++;
cd(argc,argv); // change to requested directory
dirs(1,NULL); // stat stack status
}
return 0;
}
示例7: find_and_exec
//big ass switchy thingy
int find_and_exec(const char * command_name, const char * parameters){
int ret;
if(command_name == NULL){
return 0;
}
else if(strcmp(command_name,"pwd") == 0){
return pwd();
}
else if(strcmp(command_name,"cd") == 0){
return cd(parameters);
}
else if(strcmp(command_name,"echo") == 0){
return echo(parameters);
}
else if(strcmp(command_name,"pushd") == 0){
return pushd(parameters);
}
else if(strcmp(command_name,"popd") == 0){
return popd();
}
else if(strcmp(command_name,"exit") == 0){
exitc(parameters);
}
else if(strcmp(command_name,"set") == 0){
printf("Did you mean export? If you are looking for windows try your walls\n");
return 0;
}
else if(strcmp(command_name,"history") == 0){
print_stack_lines(history);
return 0;
}
else if(strcmp(command_name,"unsetenv") == 0){
return unsetenv(parameters);
}
else {
int pid = fork();
if(pid == -1){return 1;}
else if(pid == 0){
if(parameters == NULL) {
execlp(command_name,command_name,NULL);
}
else {
execvp(command_name,split_spaces_cmd(command_name,parameters));
}
}
else {
wait(&ret);
return ret;
}
}
return 0;
}
示例8: createTestDir
QDir createTestDir()
{
auto tempDir = QDir::temp();
QProcess process;
process.start("rm -rf " + tempDir.filePath("test"));
process.waitForFinished();
tempDir.mkdir("test");
tempDir.cd("test");
return tempDir;
}
示例9: start
void start(bool read_from_file)
{
cd(""); // let shell starts from home
if(read_from_file){
// file processing functions should be called from here
shell_loop(true);
}
else{
shell_loop(false);
}
}
示例10: execute_non_forking
int execute_non_forking(char **subcmd){
int retval;
char *cmd = subcmd[0];
char **args = &subcmd[1];
if (strcmp(cmd, "exit") == 0) {
retval = exit_shell();
} else if (strcmp(cmd, "cd") == 0) {
retval = cd(args[0]);
} else {
retval = 2;
}
return retval;
}
示例11: main
/**
* Quash entry point
*
* @param argc argument count from the command line
* @param argv argument vector from the command line
* @return program exit status
*/
int main(int argc, char** argv) {
command_t cmd; //< Command holder argument
start();
struct sigaction NULL_sa;
struct sigaction sa;
sigset_t mask_set;
sigfillset(&mask_set);
sigdelset(&mask_set,SIGINT);
sigdelset(&mask_set,SIGTSTP);
sa.sa_handler = catchChild;
sigprocmask(SIG_SETMASK, &mask_set, NULL);
//TODO: this is involved withe the error 10 problem. Removing it remedies the issue for now but breaks other things.
sigaction(SIGCHLD, &sa,NULL);//child termination calls catchChild;
setenv( "WKDIR", getenv("HOME"), 1 );
puts("hOi! Welcome to Quash!");
// Main execution loop
while (is_running())
{
// NOTE: I would not recommend keeping anything inside the body of
// this while loop. It is just an example.
// The commands should be parsed, then executed.
if( !get_command(&cmd, stdin) );
else if (!strcmp(cmd.cmdstr, "q")||!strcmp(cmd.cmdstr, "exit")||!strcmp(cmd.cmdstr, "quit"))
terminate(); // Exit Quash
else if(!strcmp(cmd.execArgs[0], "set"))
set(cmd);//set environment variables
else if(!strcmp(cmd.execArgs[0], "echo"))
echo(cmd);//echos environment variables
else if(!strcmp(cmd.execArgs[0], "pwd"))
pwd(cmd);//prints current working directory
else if(!strcmp(cmd.execArgs[0], "cd"))
cd(cmd);//changes the working directory
else if(!strcmp(cmd.execArgs[0], "jobs"))
jobs();//prints out a list of currently running jobs
else if(!strcmp(cmd.execArgs[0], "kill"))
killChild(cmd);//kills specified job
else if (!strcmp(cmd.execArgs[0], "wait"))
sleep(atoi(cmd.execArgs[1]));
else if (strchr(cmd.cmdstr,'|')!= NULL)
exec_pipes(cmd);//executes piped commands
else
exec_cmd(cmd);//executes normal commands
}
return EXIT_SUCCESS;
}
示例12: mkdir
mkdir(char *dname){ //WORKS!!!
char *FileName;
struct NODE *temp;
temp = cwd;
strcpy(bname, basename(dname));
if(0 == strcmp(basename(dname), "/")){
// printf("cannot create directory '/'");
return 0;
}
if(!dname || bname[0] == '.' || bname[0] == '/'){
return 0;
}
char *character = dirname(dname);
if(strcmp(character, ".")){
printf("%s\n", character);
if(cd(&temp, character) == 0){
printf("mkdir: cannot create directory '%s': directory does not exist\n", dname);
return 0;
};
}
// printf("%s ###: ", character);
// pwd(temp);
// printf(" ###\n");
// printf("Dir: '%s' File: '%s'\n",dname, bname);
if(temp->childPtr == NULL){
temp->childPtr = (struct NODE *)malloc(sizeof(struct NODE));
strcpy(temp->childPtr->Name, bname);
temp->childPtr->parentPtr = temp;
strcpy(temp->childPtr->Type, "D");
}
else{
temp = temp->childPtr;
if(0 == strcmp(temp->Name, bname)){
printf("mkdir: cannot create directory '%s': directory exists\n", bname);
return 0;
}
while(temp->siblingPtr != NULL){
temp = temp->siblingPtr;
// printf("%s != %s\n", temp->Name, dname);
if(0 == strcmp(temp->Name, bname)){
printf("mkdir: cannot create directory '%s': directory exists\n", dname);
return 0;
}
}
temp->siblingPtr = (struct NODE *)malloc(sizeof(struct NODE));
strcpy(temp->siblingPtr->Name, bname);
temp->siblingPtr->parentPtr = temp->parentPtr;
strcpy(temp->siblingPtr->Type, "D");
}
//printf("Directory: %s Created.\n", dname);
}
示例13: main
int main(int argc, char *argv[]) {
char *delimiter_position = NULL;
char *command = NULL;
int i = 0;
if (argc < 2) {
while(1) {
if (getcwd(current_work_path, sizeof(current_work_path)) == NULL) {
break;
}
if (getlogin_r(user, sizeof(user)) != 0) {
break;
}
sprintf(PS1, "%s:%s$ ", user, current_work_path);
if (command != NULL) {
free(command);
command = NULL;
}
command = readline(PS1);
if ((command != NULL) && (*command != '\0')) {
add_history(command);
}
delimiter_position = strtok(command, " ");
while (delimiter_position != NULL) {
argv[i++] = delimiter_position;
delimiter_position = strtok(NULL, " ");
}
argv[i] = NULL;
i = 0;
if (strcmp(argv[0], "quit") == 0) {
break;
}
if (strcmp(argv[0], "cd") == 0) {
cd(argv);
continue;
}
execute(argv);
}
} else {
readopt(argc, argv);
}
return 0;
}
示例14: cd
void MainWindow::connect2mysql() {
ConnectDialog cd(this);
cd.readSettings();
if ( cd.exec() == QDialog::Accepted ) {
cd.writeSettings();
try {
md = cd.getConnection();
QMessageBox::information(this, "Connected", "Connected to MYSQL!");
} catch ( std::exception & e ) {
QMessageBox::warning(this, "Failed", e.what());
}
}
}
示例15: copy_from_ordered_range
void
PB_DS_CLASS_C_DEC::
copy_from_ordered_range(It first_it, It last_it, It other_first_it,
It other_last_it)
{
clear();
const size_type len = std::distance(first_it, last_it)
+ std::distance(other_first_it, other_last_it);
value_vector a_values = s_value_alloc.allocate(len);
iterator target_it = a_values;
It source_it = first_it;
It source_end_it = last_it;
cond_dtor<size_type> cd(a_values, target_it, len);
while (source_it != source_end_it)
{
new (const_cast<void* >(static_cast<const void* >(target_it)))
value_type(*source_it++);
++target_it;
}
source_it = other_first_it;
source_end_it = other_last_it;
while (source_it != source_end_it)
{
new (const_cast<void* >(static_cast<const void* >(target_it)))
value_type(*source_it++);
++target_it;
}
reallocate_metadata((node_update* )this, len);
cd.set_no_action();
m_a_values = a_values;
m_size = len;
m_end_it = m_a_values + m_size;
update(PB_DS_node_begin_imp(), (node_update* )this);
#ifdef _GLIBCXX_DEBUG
const_iterator dbg_it = m_a_values;
while (dbg_it != m_end_it)
{
map_debug_base::insert_new(PB_DS_V2F(*dbg_it));
dbg_it++;
}
PB_DS_CLASS_C_DEC::assert_valid();
#endif
}