Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #define DEFAULT_QUOTA_SIZ 1048576
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <dirent.h>
- #include <errno.h>
- typedef struct msg{
- char *destination;
- char *subject;
- char *text;
- }message;
- /* User Data.
- * It contains all data stored of an user.
- */
- typedef struct userData{
- char *username;
- char *password;
- long int nMessages;
- long int bytes_quota;
- message *msgs;
- }user;
- int addUser(char *username, user *users, int nAccounts){
- char *path;
- FILE *fp;
- int i,last;
- last=nAccounts-1;
- users[last].username=malloc(BUFSIZ);
- users[last].password=malloc(BUFSIZ);
- users[last].username=username;
- printf(" ___ADD_USER___\n");
- for(i=0;i<(nAccounts);i++){
- printf("username: %s\npassword: %s\nbytes_quota: %ld\nnMessages: %ld\n", users[i].username, users[i].password, users[i].bytes_quota, users[i].nMessages);
- }
- printf("Insert a password for the '%s' account: \n",users[last].username);
- scanf("%s",users[last].password);
- for(i=0;i<nAccounts;i++){
- printf("username: %s\npassword: %s\nbytes_quota: %ld\nnMessages: %ld\n", users[i].username, users[i].password, users[i].bytes_quota, users[i].nMessages);
- }
- printf("non arrivo qui-");
- users[last].bytes_quota=DEFAULT_QUOTA_SIZ; /* default quota: 1MB */
- printf("non arrivo qui-");
- path="dir/";
- /* Creating user mailbox file */
- sprintf(path,"%s",username);
- fp=fopen(path, "w");
- if(fp==NULL){
- perror("user file creation");
- return EXIT_FAILURE;
- }
- fwrite(&users[last],sizeof(user),1,fp);
- fclose(fp);
- /* Updating 'usrs' file with the new user */
- fp=fopen("dir/usrs", "a");
- if(fp==NULL){
- perror("user file creation");
- return EXIT_FAILURE;
- }
- fprintf(fp,"%s",username);
- fclose(fp);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement