Removed Common

Change-Id: I01ea8f07220375c2ad9bc0092281d4f27c642303
diff --git a/aos/scoped/BUILD b/aos/scoped/BUILD
new file mode 100644
index 0000000..04f0e06
--- /dev/null
+++ b/aos/scoped/BUILD
@@ -0,0 +1,14 @@
+package(default_visibility = ["//visibility:public"])
+
+cc_library(
+    name = "scoped_fd",
+    hdrs = [
+        "scoped_fd.h",
+    ],
+    compatible_with = [
+        "//tools:armhf-debian",
+    ],
+    deps = [
+        "//aos/logging",
+    ],
+)
diff --git a/aos/scoped/scoped_fd.h b/aos/scoped/scoped_fd.h
new file mode 100644
index 0000000..696cf3b
--- /dev/null
+++ b/aos/scoped/scoped_fd.h
@@ -0,0 +1,44 @@
+#ifndef _AOS_SCOPED_FD_
+#define _AOS_SCOPED_FD_
+
+#include <unistd.h>
+
+#include "aos/logging/logging.h"
+#include "aos/macros.h"
+
+namespace aos {
+
+// Smart "pointer" (container) for a file descriptor.
+class ScopedFD {
+ public:
+  explicit ScopedFD(int fd = -1) : fd_(fd) {}
+  ~ScopedFD() { Close(); }
+  int get() const { return fd_; }
+  int release() {
+    const int r = fd_;
+    fd_ = -1;
+    return r;
+  }
+  void reset(int new_fd = -1) {
+    if (fd_ != new_fd) {
+      Close();
+      fd_ = new_fd;
+    }
+  }
+  operator bool() const { return fd_ != -1; }
+
+ private:
+  int fd_;
+  void Close() {
+    if (fd_ != -1) {
+      if (close(fd_) == -1) {
+        PLOG(WARNING, "close(%d) failed", fd_);
+      }
+    }
+  }
+  DISALLOW_COPY_AND_ASSIGN(ScopedFD);
+};
+
+}  // namespace aos
+
+#endif  // _AOS_SCOPED_FD_
diff --git a/aos/scoped/scoped_ptr.h b/aos/scoped/scoped_ptr.h
new file mode 100644
index 0000000..336e73b
--- /dev/null
+++ b/aos/scoped/scoped_ptr.h
@@ -0,0 +1,43 @@
+#ifndef AOS_SCOPED_PTR_H_
+#define AOS_SCOPED_PTR_H_
+
+#include "aos/macros.h"
+
+namespace aos {
+
+// A simple scoped_ptr implementation that works under both linux and vxworks.
+template<typename T>
+class scoped_ptr {
+ public:
+  typedef T element_type;
+  
+  explicit scoped_ptr(T *p = NULL) : p_(p) {}
+  ~scoped_ptr() {
+    delete p_;
+  }
+
+  T &operator*() const { return *p_; }
+  T *operator->() const { return p_; }
+  T *get() const { return p_; }
+
+  operator bool() const { return p_ != NULL; }
+
+  void swap(scoped_ptr<T> &other) {
+    T *temp = other.p_;
+    other.p_ = p_;
+    p_ = other.p_;
+  }
+  void reset(T *p = NULL) {
+    if (p_ != NULL) delete p_;
+    p_ = p;
+  }
+
+ private:
+  T *p_;
+
+  DISALLOW_COPY_AND_ASSIGN(scoped_ptr<T>);
+};
+
+}  // namespace aos
+
+#endif  // AOS_SCOPED_PTR_H_