Skip to content

Commit

Permalink
Use stringByAppendingPathComponent instead of String concatenation. #4
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFox committed Nov 6, 2016
1 parent 58676e2 commit 595ac2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ project(CmusControl)
set(PROJECT_RELEASE_ID 3)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 2)
set(PROJECT_VERSION_APPENDIX "")
set(PROJECT_VERSION_PATCH 3)
set(PROJECT_VERSION_APPENDIX "-dev")
set(PROJECT_COPYRIGHT "Copyright (C) 2015 Christian Mayer <https://fox21.at>")
set(PROJECT_USE_PID_FILE 0)
set(PROJECT_INSTALL_BIN_DST_PATH "/usr/local/bin")
Expand Down
9 changes: 4 additions & 5 deletions src/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ int main(int argc, const char *argv[]){
@autoreleasepool{

#ifdef PROJECT_USE_PID_FILE
DLog(@"with PROJECT_USE_PID_FILE");

NSProcessInfo* pInfo = [NSProcessInfo processInfo];
NSString* processName = [pInfo processName];
int processId = [pInfo processIdentifier];
NSString* processIdStr = [[NSString alloc] initWithFormat:@"%d", processId];

NSString* pidFileDir = @"/var/run";
// NSString* pidFileDir = @"/tmp";
NSString* pidFilePath = [[NSString alloc] initWithFormat:@"%@/%@.pid", pidFileDir, processName];
NSString* pidFilePath = [[pidFileDir stringByAppendingPathComponent:processName]
stringByAppendingPathExtension:@"pid"];
DLog(@"use pid file: %@", pidFilePath);

NSFileManager* filemgr = [NSFileManager defaultManager];
if([filemgr isWritableFileAtPath:pidFileDir]){
Expand All @@ -30,7 +29,7 @@ int main(int argc, const char *argv[]){
DLog(@"WARNING: Can't write in %@", pidFileDir);
}
#else
DLog(@"no PROJECT_USE_PID_FILE");
DLog(@"no pid file");
#endif

// CCAppDelegate* delegate = [CCAppDelegate new];
Expand Down

0 comments on commit 595ac2d

Please sign in to comment.