56
56
#include <errno.h>
57
57
#include <debug.h>
58
58
59
-
60
59
#if !defined(CONFIG_DISABLE_MOUNTPOINT )
61
60
# ifdef CONFIG_FS_READABLE /* Need at least one filesytem in configuration */
62
61
# include <sys/mount.h>
@@ -240,47 +239,47 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
240
239
241
240
if ((buf .st_mode & S_IRUSR ) != 0 )
242
241
{
243
- details [1 ]= 'r' ;
242
+ details [1 ] = 'r' ;
244
243
}
245
244
246
245
if ((buf .st_mode & S_IWUSR ) != 0 )
247
246
{
248
- details [2 ]= 'w' ;
247
+ details [2 ] = 'w' ;
249
248
}
250
249
251
250
if ((buf .st_mode & S_IXUSR ) != 0 )
252
251
{
253
- details [3 ]= 'x' ;
252
+ details [3 ] = 'x' ;
254
253
}
255
254
256
255
if ((buf .st_mode & S_IRGRP ) != 0 )
257
256
{
258
- details [4 ]= 'r' ;
257
+ details [4 ] = 'r' ;
259
258
}
260
259
261
260
if ((buf .st_mode & S_IWGRP ) != 0 )
262
261
{
263
- details [5 ]= 'w' ;
262
+ details [5 ] = 'w' ;
264
263
}
265
264
266
265
if ((buf .st_mode & S_IXGRP ) != 0 )
267
266
{
268
- details [6 ]= 'x' ;
267
+ details [6 ] = 'x' ;
269
268
}
270
269
271
270
if ((buf .st_mode & S_IROTH ) != 0 )
272
271
{
273
- details [7 ]= 'r' ;
272
+ details [7 ] = 'r' ;
274
273
}
275
274
276
275
if ((buf .st_mode & S_IWOTH ) != 0 )
277
276
{
278
- details [8 ]= 'w' ;
277
+ details [8 ] = 'w' ;
279
278
}
280
279
281
280
if ((buf .st_mode & S_IXOTH ) != 0 )
282
281
{
283
- details [9 ]= 'x' ;
282
+ details [9 ] = 'x' ;
284
283
}
285
284
286
285
nsh_output (vtbl , " %s" , details );
@@ -561,7 +560,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
561
560
562
561
/* Construct the full path to the new file */
563
562
564
- allocpath = nsh_getdirpath (vtbl , destpath , basename (argv [1 ]) );
563
+ allocpath = nsh_getdirpath (vtbl , destpath , basename (argv [1 ]));
565
564
if (!allocpath )
566
565
{
567
566
nsh_error (vtbl , g_fmtcmdoutofmemory , argv [0 ]);
@@ -581,6 +580,14 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
581
580
}
582
581
}
583
582
583
+ /* Check if the destination does not match the source */
584
+
585
+ if (strcmp (destpath , srcpath ) == 0 )
586
+ {
587
+ nsh_error (vtbl , g_fmtsyntax , argv [0 ]);
588
+ goto errout_with_allocpath ;
589
+ }
590
+
584
591
/* Now open the destination */
585
592
586
593
wrfd = open (destpath , oflags , 0666 );
@@ -592,7 +599,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
592
599
593
600
/* Now copy the file */
594
601
595
- for (;; )
602
+ for (; ; )
596
603
{
597
604
int nbytesread ;
598
605
int nbyteswritten ;
@@ -644,9 +651,10 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
644
651
}
645
652
else
646
653
{
647
- /* Read error */
654
+ /* Read error */
648
655
649
- nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "write" , NSH_ERRNO );
656
+ nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "write" ,
657
+ NSH_ERRNO );
650
658
}
651
659
652
660
goto errout_with_wrfd ;
@@ -678,6 +686,7 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
678
686
{
679
687
nsh_freefullpath (srcpath );
680
688
}
689
+
681
690
errout :
682
691
return ret ;
683
692
}
@@ -862,7 +871,8 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
862
871
/* Get the losetup options: Two forms are supported:
863
872
*
864
873
* losmart -d <loop-device>
865
- * losmart [-m minor-number] [-o <offset>] [-e erasesize] [-s sectsize] [-r] <filename>
874
+ * losmart [-m minor-number] [-o <offset>] [-e erasesize] [-s sectsize]
875
+ * [-r] <filename>
866
876
*
867
877
* NOTE that the -o and -r options are accepted with the -d option, but
868
878
* will be ignored.
@@ -955,7 +965,8 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
955
965
{
956
966
/* Tear down the loop device. */
957
967
958
- ret = ioctl (fd , SMART_LOOPIOC_TEARDOWN , (unsigned long )((uintptr_t ) loopdev ));
968
+ ret = ioctl (fd , SMART_LOOPIOC_TEARDOWN ,
969
+ (unsigned long )((uintptr_t ) loopdev ));
959
970
if (ret < 0 )
960
971
{
961
972
nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "ioctl" , NSH_ERRNO );
@@ -973,7 +984,8 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
973
984
setup .offset = offset ; /* An offset that may be applied to the device */
974
985
setup .readonly = readonly ; /* True: Read access will be supported only */
975
986
976
- ret = ioctl (fd , SMART_LOOPIOC_SETUP , (unsigned long )((uintptr_t )& setup ));
987
+ ret = ioctl (fd , SMART_LOOPIOC_SETUP ,
988
+ (unsigned long )((uintptr_t )& setup ));
977
989
if (ret < 0 )
978
990
{
979
991
nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "ioctl" , NSH_ERRNO );
@@ -1091,7 +1103,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1091
1103
switch (option )
1092
1104
{
1093
1105
case 'l' :
1094
- lsflags |= (LSFLAGS_SIZE | LSFLAGS_LONG );
1106
+ lsflags |= (LSFLAGS_SIZE | LSFLAGS_LONG );
1095
1107
break ;
1096
1108
1097
1109
case 'R' :
@@ -1169,7 +1181,8 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1169
1181
* file
1170
1182
*/
1171
1183
1172
- ret = ls_handler (vtbl , fullpath , NULL , (FAR void * )((uintptr_t )lsflags ));
1184
+ ret = ls_handler (vtbl , fullpath , NULL ,
1185
+ (FAR void * )((uintptr_t )lsflags ));
1173
1186
}
1174
1187
else
1175
1188
{
@@ -1178,7 +1191,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1178
1191
nsh_output (vtbl , "%s:\n" , fullpath );
1179
1192
1180
1193
ret = nsh_foreach_direntry (vtbl , "ls" , fullpath , ls_handler ,
1181
- (FAR void * )((uintptr_t )lsflags ));
1194
+ (FAR void * )((uintptr_t )lsflags ));
1182
1195
if (ret == OK && (lsflags & LSFLAGS_RECURSIVE ) != 0 )
1183
1196
{
1184
1197
/* Then recurse to list each directory within the directory */
@@ -1282,7 +1295,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1282
1295
1283
1296
/* There should be exactly one parameter left on the command-line */
1284
1297
1285
- if (optind == argc - 1 )
1298
+ if (optind == argc - 1 )
1286
1299
{
1287
1300
fullpath = nsh_getfullpath (vtbl , argv [optind ]);
1288
1301
if (fullpath == NULL )
@@ -1480,7 +1493,8 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1480
1493
nsh_error (vtbl , "Sector size must be 256-16384\n" );
1481
1494
return EINVAL ;
1482
1495
}
1483
- if (sectorsize & (sectorsize - 1 ))
1496
+
1497
+ if (sectorsize & (sectorsize - 1 ))
1484
1498
{
1485
1499
nsh_error (vtbl , "Sector size must be power of 2\n" );
1486
1500
return EINVAL ;
@@ -1523,7 +1537,8 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1523
1537
#endif
1524
1538
if (ret < 0 )
1525
1539
{
1526
- nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "mksmartfs" , NSH_ERRNO );
1540
+ nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "mksmartfs" ,
1541
+ NSH_ERRNO );
1527
1542
}
1528
1543
}
1529
1544
@@ -1594,6 +1609,7 @@ int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1594
1609
ssize_t len ;
1595
1610
1596
1611
/* readlink <link> */
1612
+
1597
1613
/* Get the fullpath to the directory */
1598
1614
1599
1615
fullpath = nsh_getfullpath (vtbl , argv [1 ]);
@@ -1734,7 +1750,7 @@ int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
1734
1750
* files.
1735
1751
*/
1736
1752
1737
- for (;; )
1753
+ for (; ; )
1738
1754
{
1739
1755
char buf1 [128 ];
1740
1756
char buf2 [128 ];
0 commit comments