int main(void) { char write_msg[BUFFER_SIZE] = "Greetings"; char read_msg[BUFFER_SIZE]; int fd1[2], fd2[2]; pid_t pid; /* create the pipe */ if (pipe(fd1) == -1) { fprintf(stderr, "Pipe Failed"); return 1; } if (pipe(fd2) == -1) { fprintf(stderr, "Pipe Failed"); return 1; } /* Fork a child process */ pid = fork(); if (pid < 0) { fprintf(stderr, "Fork Failed"); return 1; } if (pid > 0) { close(fd1[READ_END]); close(fd2[WRITE_END]); write(fd1[WRITE_END], write_msg, strlen(write_msg) + 1); close(fd1[WRITE_END]); waitpid(pid, NULL, 0); read(fd2[READ_END], read_msg, BUFFER_SIZE); close(fd2[READ_END]); printf("Parent read %s", read_msg); } else { close(fd2[READ_END]); close(fd1[WRITE_END]); read(fd1[READ_END], read_msg, BUFFER_SIZE); close(fd1[READ_END]); int len = strlen(read_msg); int i; for (i=0; i < len; i++) { write_msg[i] = reverseCase(write_msg[i]); } write(fd2[WRITE_END], write_msg, strlen(write_msg) + 1); close(fd2[WRITE_END]); _exit(0); } return 0; }
void ChangeCasePluginEditorInterface::exec() { switch (mType) { case Unknown: qCDebug(KMAIL_EDITOR_CHANGECASE_PLUGIN_LOG) << " There is an error here. We can't call this plugin with unknown type"; break; case UpperCase: upperCase(); break; case LowerCase: lowerCase(); break; case SentenseCase: sentenceCase(); break; case ReverseCase: reverseCase(); break; } mType = Unknown; }