Skip to content

Conversation

@pipichinka
Copy link
Owner

No description provided.

lab3.2 Outdated
perror("myls: openning dir");
return 1;
}
struct dirent* ep;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять не понятно, что за ep)
Всё же, не стоит жертвовать читаемостью кода ради сокращения нескольких букв в названии переменной

perror("mymkdir: removing dir");
return 1;
}
return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И снова какие-то непонятные 0 и 1)

int mycat(char* name){
FILE* file = fopen(name, "r");
if (file == NULL){
perror("mycat: openning file:");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А тут типо норм, файл не открылся - написали сообщение и пошли дальше?

lab3.2 Outdated
size_t size;
char buffer[4096];
while((size = fread(buffer, sizeof(char), 4096, file))){
if (write(0,buffer,size )== 0){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну, ты, вроде, везде пользовался буферизированным вводом/выводом с fread/fwrite. Почему вдруг тут решил напрямую системные вызовы дергать? Почему тот же fwrite() не использовать?

lab3.2 Outdated
buffer[len] = '\n';
buffer[len +1] = '\0';
if (write(1, buffer, len + 1) == 0){
perror("mycatvsl ");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять пробел в конце сообщения)

lab3.2 Outdated
}

printf("%s info: number of hard links: %lu.", name, st.st_nlink);
char rights[10];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты можешь при объявлении массива его сразу нулями инициализировать char rights[10] = {0};, тогда не придется потом последний символ занулять

lab3.2 Outdated
perror("mychmod: getting info about file");
return 1;
}
st.st_mode = (st.st_mode >> 8) << 8;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень странно, почему сдвиги на 8, когда бит используется 9..
Можно было еще написать что-то типа st.st_mode &= ~((mode_t) 0777);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И если в своем коде используешь какие-то такие неочевидные шаги, лучше всегда оставлять комментарии, почему здесь именно так. Ибо ты сам будешь читать код через месяц и уже забудешь, о чем здесь вообще речь была, почему здесь 8/9/15, а не 379, например

lab3.2 Outdated
}

for (int i = 0; i < 3; i++){
st.st_mode = rights[3 * i] == 'r' ? (st.st_mode | (0400 >> (3 * i))) : st.st_mode;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если хочется коротенько и красиво, то можно вот так сделать)
st.st_mode |= rights[3 * i] == 'r' ? (0400 >> (3 * i)) : 0;

lab3.2 Outdated
// printf("argv[0] %s\n", argv[0]);
// }
char* exe_name = strrchr(argv[0], '/') + 1;
if (exe_name == (char* ) NULL + 1 ){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выглядит это, конечно, страшновато)
Вообще, есть уже готовая функция, которая по пути вернет тебе имя файла. Советую поискать, посмотреть)

lab3.2 Outdated

if (!strcmp(exe_name, "mymkdir")){
if (argc != 2){
fprintf(stderr, "ivalid number of arguments(requars 1 arg: dir name)");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще, правильно пишется require, а не requar. Лучше будет написать required 1 arg

lab3.2 Outdated
}


int myrm(char* name){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А вот твои изменения, в которых ты половину лабы удалил))

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Красивое)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants